Submission #1064188

#TimeUsernameProblemLanguageResultExecution timeMemory
1064188BABY_GANGSTERFlooding Wall (BOI24_wall)C++14
0 / 100
1 ms604 KiB
//https://www.instagram.com/_modwwe/ #pragma GCC optimize("Ofast,unroll-loops") #include<bits/stdc++.h> #define int long long //#define ll long long #define down cout<<'\n'; #define debug cout<<" cucuucucuuu",down #define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define modwwe int t;cin>>t; while(t--) #define bit(i,j) (i>>j&1) #define sobit(a) __builtin_popcountll(a) #define task "test" #define fin(x) freopen(x".inp","r",stdin) #define fou(x) freopen(x".ans","w",stdout) #define pb push_back #define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms"; using namespace std; void phongbeo(); const int inf=1e9; const int mod2=1e9+7; const int mod1=998244353; struct icd { long double a; int b; }; struct ib { int a; int b; }; struct ic { int a,b,c; }; struct id { int a,b,c,d; }; struct ie { int a,b,c,d,e; }; int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,l,r,mid; int i,s10,s12; int kk; int el=29; main() { #ifndef ONLINE_JUDGE //fin(task),fou(task); #endif NHP /// cin>>s1; // modwwe phongbeo(); } ic mer(ic a,ic b) { return {a.a+b.a,a.b+b.b,a.c+b.c}; } vector<int> v; struct IT { ic t[4000001]; int t2[4000001]; int t3[4000001]; void build(int node,int l,int r) { t2[node]=1; t3[node]=0; t[node]={0,0,0}; if(l==r) return; int mid=l+r>>1; build(node<<1,l,mid); build(node<<1|1,mid+1,r); } void ff(int x) { for(int i=x*2; i<=x*2+1; i++) { if(t2[i]==0) continue; t[i].c*=t2[x]; t[i].c%=mod2; t[i].a=t[i].a-t3[x]*t[i].b+t[i].c; t[i].b=t[i].b*t2[x]; t3[i]+=t3[x]*t2[i]; t2[i]*=t2[x]; t[i].a%=mod2; t[i].b%=mod2; t2[i]%=mod2; } t2[x]=1; t3[x]=0; } void upd5(int node,int l,int r,int l1,int r1,int x) { if(l>r1||r<l1||t2[node]==0) return; if(l>=l1&&r<=r1) { t2[node]=t2[node]*2%mod2; t3[node]+=x; t3[node]%=mod2; t[node].c=t[node].c*2%mod2; t[node].a=t[node].a*2; t[node].a=t[node].a-x*t[node].b+t[node].c; t[node].a%=mod2; t[node].b=t[node].b*2%mod2; return; } if(t3[node]!=0) ff(node); int mid=l+r>>1; upd5(node<<1,l,mid,l1,r1,x); upd5(node<<1|1,mid+1,r,l1,r1,x); t[node]=mer(t[node<<1],t[node<<1|1]); } void upd(int node,int l,int r,int l1,int r1,int x) { if(l>r1||r<l1||t2[node]==0) return; if(l>=l1&&r<=r1) { t2[node]=t2[node]*2%mod2; t3[node]+=x; t3[node]%=mod2; t[node].c=t[node].c*2%mod2; t[node].a=t[node].a*2; t[node].a=t[node].a-x*t[node].b+t[node].c; t[node].a%=mod2; t[node].b=t[node].b*2%mod2; return; } if(t3[node]!=0) ff(node); int mid=l+r>>1; upd(node<<1,l,mid,l1,r1,x); upd(node<<1|1,mid+1,r,l1,r1,x); t[node]=mer(t[node<<1],t[node<<1|1]); } void upd4(int node,int l,int r,int l1,int r1,int x) { if(l>r1||r<l1||t2[node]==0)return; if(l>=l1&&r<=r1) { t[node].a=t[node].a+t[node].c-x*t[node].b; t[node].a%=mod2; t3[node]+=x; t3[node]%=mod2; return; } if(t3[node]!=0) ff(node); int mid=l+r>>1; upd4(node<<1,l,mid,l1,r1,x); upd4(node<<1|1,mid+1,r,l1,r1,x); t[node]=mer(t[node<<1],t[node<<1|1]); } void upd2(int node,int l,int r,int l1,ib x) { if(t2[node]==0) return; if(l==r) { t[node].a+=x.a; t[node].c+=x.b*v[l-1]; t[node].b+=x.b; return; } if(t3[node]!=0) ff(node); int mid=l+r>>1; if(l1<=mid)upd2(node<<1,l,mid,l1,x); else upd2(node<<1|1,mid+1,r,l1,x); t[node]=mer(t[node<<1],t[node<<1|1]); } void upd3(int node,int l,int r,int l1,int r1) { if(l>r1||r<l1||t2[node]==0) return; if(l>=l1&&r<=r1) { t2[i]=0; t[node]= {0,0,0}; return; } int mid=l+r>>1; if(t3[node]!=0) ff(node); upd3(node<<1,l,mid,l1,r1); upd3(node<<1|1,mid+1,r,l1,r1); t[node]=mer(t[node<<1],t[node<<1|1]); } ic get(int node,int l,int r,int l1,int r1) { if(l>r1||r<l1||t2[node]==0) return{0,0,0}; if(l>=l1&&r<=r1)return t[node]; if(t3[node]!=0) ff(node); int mid=l+r>>1; return mer(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1)); } }st; ib a[500001]; struct cc{ ic a,b; }c[500001]; void phongbeo() { cin>>n; for(int i=1; i<=n; i++) cin>>a[i].a,v.pb(a[i].a); for(int i=1; i<=n; i++) cin>>a[i].b,v.pb(a[i].b); sort(v.begin(),v.end()); v.erase(unique(v.begin(), v.end()), v.end()); m=v.size(); for(int i=1;i<=n;i++) { if(a[i].a>a[i].b) swap(a[i].a,a[i].b); a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1; a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1; } st.build(1,1,m); st.upd2(1,1,m,a[n].a,{0,1}); st.upd2(1,1,m,a[n].b,{0,1}); c[n].a.b=1; c[n].b.b=1; for(int i=n-1;i>=1;--i) { ic x=st.get(1,1,m,1,a[i].a-1); ic x2=st.get(1,1,m,1,a[i].b-1); c[i].a=x; c[i].b=x2; st.upd3(1,1,m,1,a[i].a-1); st.upd4(1,1,m,a[i].a,a[i].b-1,v[a[i].a-1]); st.upd(1,1,m,a[i].b,m,v[a[i].a-1]+v[a[i].b-1]); st.upd2(1,1,m,a[i].a,{x.a,x.b}); st.upd2(1,1,m,a[i].b,{x2.a,x2.b}); } st.build(1,1,m); for(int i=0;i<=n-1;i++) { if(i==0)s4=(s4+c[1].a.a+c[1].b.a)%mod2; else { if(i==1){st.upd2(1,1,m,a[1].a,{0,1}); st.upd2(1,1,m,a[1].b,{0,1}); } else { ic x=st.get(1,1,m,1,a[i].a-1); ic x2=st.get(1,1,m,1,a[i].b-1); st.upd3(1,1,m,1,a[i].a-1); st.upd4(1,1,m,a[i].a,a[i].b-1,v[a[i].a-1]); st.upd(1,1,m,a[i].b,m,v[a[i].a-1]+v[a[i].b-1]); st.upd2(1,1,m,a[i].a,{x.a,x.b}); st.upd2(1,1,m,a[i].b,{x2.a,x2.b}); } ic x=st.get(1,1,m,a[i].a,a[i].a); ic x2=st.get(1,1,m,a[i].b,a[i].b); if(a[i+1].a>=a[i].a) { s4=(s4+c[i+1].a.a*x.b+x.a*c[i+1].a.b)%mod2; } if(a[i+1].b>=a[i].a) { s4=(s4+c[i+1].b.a*x.b+x.a*c[i+1].b.b)%mod2; } if(a[i+1].a>=a[i].b) { s4=(s4+c[i+1].a.a*x2.b+x2.a*c[i+1].a.b)%mod2; } if(a[i+1].b>=a[i].b) { s4=(s4+c[i+1].b.a*x2.b+x2.a*c[i+1].b.b)%mod2; } } } cout<<s4; }

Compilation message (stderr)

Main.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main()
      | ^~~~
Main.cpp: In member function 'void IT::build(long long int, long long int, long long int)':
Main.cpp:77:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 | int mid=l+r>>1;
      |         ~^~
Main.cpp: In member function 'void IT::upd5(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:117:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  117 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In member function 'void IT::upd(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:139:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  139 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In member function 'void IT::upd4(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:156:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  156 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In member function 'void IT::upd2(long long int, long long int, long long int, long long int, ib)':
Main.cpp:172:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  172 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In member function 'void IT::upd3(long long int, long long int, long long int, long long int, long long int)':
Main.cpp:187:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  187 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In member function 'ic IT::get(long long int, long long int, long long int, long long int, long long int)':
Main.cpp:198:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  198 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In function 'void phongbeo()':
Main.cpp:211:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  211 |     for(int i=1; i<=n; i++)
      |     ^~~
Main.cpp:213:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  213 |         sort(v.begin(),v.end());
      |         ^~~~
#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...