Submission #336382

#TimeUsernameProblemLanguageResultExecution timeMemory
336382KerimIntergalactic ship (IZhO19_xorsum)C++17
100 / 100
202 ms11336 KiB
#include "bits/stdc++.h" #define MAXN 100029 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} int arr[MAXN],tmp[7],l[MAXN],r[MAXN],val[MAXN]; vector<int>adj[MAXN]; int cnt[MAXN][7],cntt[MAXN][7][7],cur[7][7],ans[MAXN]; void upd(int x,int val){ for(int i=0;i<7;i++) if(x>>i&1) tmp[i]+=val; } void upd1(int x,int val,int ind){ for(int i=0;i<7;i++) if(x>>i&1) for(int j=0;j<7;j++) if(x>>j&1) cntt[ind][i][j]+=val; } vector<int>add[MAXN],rem[MAXN]; int mod(ll x){ return (x%INF); } int main(){ // freopen("file.in", "r", stdin); int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",arr+i); int q; scanf("%d",&q); for(int i=0;i<q;i++){ scanf("%d%d%d",l+i,r+i,val+i); add[l[i]].pb(i); rem[r[i]].pb(i); } for(int i=1;i<=n;i++){ tr(it,add[i]) upd(val[*it],+1); for(int j=0;j<7;j++) cnt[i][j]=tmp[j]; tr(it,rem[i]) upd(val[*it],-1); } ll cost;int ii,jj,ca,cb,ins; for(int i=1;i<=n;i++){ tr(it,add[i]) upd1(val[*it],+1,i); memset(cur,0,sizeof cur); for(int j=1;j<=i;j++){ cost=j*(n-i+1); if(i!=j)cost*=2; for(int a=0;a<7;a++){//a'th bit in j for(int b=0;b<7;b++){//b'th bit in i cur[a][b]+=cntt[j][a][b]; cb=(arr[i]>>b&1);ca=(arr[j]>>a&1); ins=a+b+q-2; jj=cnt[j][a]-cur[a][b]; ii=cnt[i][b]-cur[a][b]; assert(ii>=0 and jj>=0); if(ii and jj) ans[ins]+=cost; else if(ii){ if(cur[a][b]) ans[ins]+=cost; else if(ca) ans[ins+1]+=cost; } else if(jj){ if(cur[a][b]) ans[ins]+=cost; else if(cb) ans[ins+1]+=cost; } else{ if(ca==cb){ if(cur[a][b]) ans[ins+1]+=cost; else if(ca and cb) ans[ins+2]+=cost; } } for(int mod=0;mod<3;mod++) if(ans[ins+mod]>=INF) ans[ins+mod]-=INF; } } } tr(it,rem[i]) upd1(val[*it],-1,l[*it]); } int pw=1,res=0; for(int i=0;i<q+14;i++) res=mod(res+pw*1LL*ans[i]),pw=mod(pw+pw); printf("%d\n",res); return 0; }

Compilation message (stderr)

xorsum.cpp: In function 'int main()':
xorsum.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
xorsum.cpp:44:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |      scanf("%d",arr+i);
      |      ~~~~~^~~~~~~~~~~~
xorsum.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
xorsum.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |   scanf("%d%d%d",l+i,r+i,val+i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...