最近被四区题暴虐。。。
题意:lyk拥有一个区间。
# include # include # include # include # include # include # include # include # include # include <set> # include # include using namespace std; # define lowbit(x) ((x)&(-x)) # define pi acos(-1.0) # define eps 1e-8 # define MOD 1000000007 # define INF 1000000000 # define mem(a,b) memset(a,b,sizeof(a)) # define FOR(i,a,n) for(int i=a; i<=n; ++i) # define FO(i,a,n) for(int i=a; ii) # define bug puts("H"); # define lch p<<1,l,mid # define rch p<<1|1,mid+1,r # define mp make_pair # define pb push_back typedef pair<int,int> PII; typedef vector<int> VI; # pragma comment(linker, "/STACK:1024000000,1024000000") typedef long long LL; inline int Scan() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();} return x*f; } inline void Out(int a) { if(a<0) {putchar('-'); a=-a;} if(a>=10) Out(a/10); putchar(a%10+'0'); } const int N=100005; //Code begin... int R[32][N], L[32][N], n, mod[65]; LL ans; bool wei[32][N]; void init(){ mod[0]=1; FOR(i,1,64) mod[i]=(mod[i-1]<<1)%MOD; FO(i,0,32) { int l=1, r=1; while (l<=n) { if (!wei[i][l]) L[i][l]=0; else { r=max(r,l); while (r1]) ++r; L[i][l]=r; } ++l; } } FO(i,0,32) { int l=1, r=1; while (l<=n) { if (wei[i][l]) R[i][l]=l; else { r=max(l,r); while (r<=n&&!wei[i][r]) ++r; R[i][l]=r; } ++l; } } } void sol(){ FO(i,0,32) FOR(j,1,n) { if (!wei[i][j]) continue; FO(k,0,32) { if (R[k][j]>L[i][j]) continue; ans=(ans+(LL)(L[i][j]-R[k][j]+1)*mod[i+k])%MOD; } } } int main () { int x; n=Scan(); FOR(i,1,n) { x=Scan(); FO(j,0,32) wei[j][i]=x%2, x/=2; } init(); sol(); printf("%lld\n",ans); return 0; }
转载于:https://www.cnblogs.com/lishiyao/p/7128453.html