csp36-5 梦魔
题干
https://sim.csp.thusaac.com/contest/36/problem/4
30分作答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include<bits/stdc++.h> using namespace std;
int n,q; const int N=2e6+5; int a[N],b[N];
int a_new[N],b_new[N]; bool check(long long bb,int i){ int l=i,r=i+1; while(l>=0&&r<n){ if(a_new[l]<=a_new[r]){ if(bb<a_new[l]) return false; else{ bb+=b_new[l]; l--; } }else{ if(bb<a_new[r]) return false; else{ bb+=b_new[r]; r++; } } } while(l>=0){ if(bb<a_new[l]) return false; else{ bb+=b_new[l]; l--; } } while(r<n){ if(bb<a_new[r]) return false; else{ bb+=b_new[r]; r++; } }
return true; }
void work(){ cin>>n; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i];
cin>>q; while(q--){ int k; cin>>k;
for(int i=0;i<n;i++){ a_new[i]=a[i]; b_new[i]=b[i]; }
while(k--){ int j,aa,bb; cin>>j>>aa>>bb; a_new[j-1]=aa; b_new[j-1]=bb; }
int amax=-1; for(int i=0;i<n;i++) amax=max(amax,a_new[i]);
int ans=0; for(int i=0;i<n-1;i++){ int l=0,r=amax; while(l<r){ int mid=l+r>>1; if(check(mid,i)) r=mid; else l=mid+1; } ans^=l; }
cout<<ans<<endl; }
}
int main(){ work(); return 0; }
|