QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401844 | #8540. Splitting Haybales | Network_Error | 9.090909 | 13ms | 24244kb | C++14 | 1.6kb | 2024-04-29 15:34:19 | 2024-04-29 15:34:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define int long long
const int N=200000,B=500,Db=N/B+1;vector<int> g[N+N+5];
int n,q,a[N+5],s[N+5],tot,L[Db+5],R[Db+5],bel[N+5],tr[Db+5][N+N+5];/*[0,N+N]->[-N,N]*/
void dfs(int*ans,int u,int x){
ans[u]=x;for(auto v:g[u])dfs(ans,v,1-x);
}
int calc(int l,int r,int x){
if(bel[l]==bel[r]){
for(int i=l;i<=r;i++)x=x<=0?x+a[i]:x-a[i];return x;
}
int bl=bel[l];
while(bel[l]==bl)x=x<=0?x+a[l]:x-a[l],l++;
for(int i=bel[l];i<bel[r];i++)x=tr[i][x+N];
l=L[bel[r]];while(l<=r)x=x<=0?x+a[l]:x-a[l],l++;return x;
}
void work(){
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i],s[i]=s[i-1]+a[i];
for(int i=1;i<=n;i++)bel[i]=(i-1)/B+1;tot=bel[n];
for(int i=1;i<=tot;i++)L[i]=R[i-1]+1,R[i]=i*B;R[tot]=n;
for(int _=1;_<=tot;_++){
for(int i=0;i<=N+N;i++)g[i].clear();
int mid=N,l=0,r=N+N;
for(int i=L[_];i<=R[_];i++){
assert(l!=mid);
if(r<=mid)mid-=a[i];else mid+=a[i];
if(l<=mid&&mid<r){
if(mid-l+1<=r-mid){
for(int i=l;i<=mid;i++)g[mid+mid-i+1].pb(i);l=mid+1;
}else{
for(int i=mid+1;i<=r;i++)g[mid+mid-i+1].pb(i);r=mid;
}
}
}
for(int i=l;i<=r;i++)dfs(tr[_],i,i-mid);
}
cin>>q;while(q--){
int l,r,x;
cin>>l>>r>>x;
while(l<=r&&abs(x)>a[l])x=x<=0?x+a[l]:x-a[l],l++;
if(l>r)cout<<x<<'\n';else cout<<calc(l,r,x)<<'\n';
}
}
signed main(){
ios::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int T=1;while(T--)work();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.54545
Accepted
time: 13ms
memory: 22832kb
input:
2 3 1 15 1 1 -2 1 1 -1 1 1 0 1 1 1 1 1 2 1 2 -2 1 2 -1 1 2 0 1 2 1 1 2 2 2 2 -2 2 2 -1 2 2 0 2 2 1 2 2 2
output:
1 2 3 -2 -1 0 1 2 -1 0 -1 0 1 0 1
result:
ok 15 lines
Test #2:
score: 4.54545
Accepted
time: 3ms
memory: 24244kb
input:
5 4 4 3 1 1 7 1 1 20 1 2 20 1 5 20 1 1 0 1 5 0 1 4 0 3 5 2
output:
16 12 7 4 1 2 1
result:
ok 7 lines
Test #3:
score: 0
Memory Limit Exceeded
input:
200000 199998 199997 199996 199995 199994 199994 199993 199992 199992 199991 199991 199990 199990 199988 199987 199986 199986 199985 199984 199983 199982 199980 199979 199979 199976 199976 199975 199974 199974 199974 199974 199972 199971 199970 199970 199970 199969 199968 199968 199967 199967 199967...
output:
-42604 0 15469 63587 -152233 -102062 -1 -12287 -26445 -94203962 26375 0 36993 93272 -44075 1 -13074 -75312 -33791 -23830 -1 2 -76892 1711 111108 338346276 -1 -22116 2 27682 9805 -19331 -2227 34998 -1 -72252 -71143 -96720663 1 -26095472 -4030 1 -11544 0 111439361 -37352 -1362 -72042 -37511 42334 -735...
result:
Test #4:
score: 0
Time Limit Exceeded
input:
200000 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169 199169...
output:
23636 39727 -5717 -149629 -68432 -107547 -5400 11159 13869 1079 40743 -1628 -65835 -29812 -11142 31333 1131 -107538 -15101 -68143 -41220 37 -15566 27253 -86354 -1867 -9261 160 16877 -20366 1112 4359 24979 1 13173 27970 33203 868 -45106 14917 838 -44013 -32700 580138178 1275 -33860 -18067 1566 -10410...
result:
Test #5:
score: 0
Time Limit Exceeded
input:
200000 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702 196702...
output:
57359 611 -4892 -178757730 42877 -667 4884 1795 13188 6598 138304 31855 -931 10052 -1113 -133186 40165 58151 -3832 -59867 2297 2169 -93321 1299 153093 45569 1061 69503 -12063 -59018 -847 -202330620 69812 -46500 -80543 -63807 277 46255 18862 94952 68262 1698 26207 -3046 10112 -17839 -804419670 -25272...
result:
Test #6:
score: 0
Time Limit Exceeded
input:
200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
80942 1 79697 -245062 -138409 0 -90287 -58075 0 1 200556 58954 -140119 1 1 326117 -73901 -76225 -97605 -223478 -175026 47817 1 -30451 0 -145315 1 273031 1 132933 0 -71358 -17522 263820 5761 1 130689 363960 0 27845 -337912 1 112360 0 0 -216292 -164215 319627 0 314753 1 -106547 0 -154442 0 -148812 184...
result:
Test #7:
score: 0
Time Limit Exceeded
input:
200000 200000 199999 199991 199988 199980 199971 199967 199959 199946 199936 199934 199934 199926 199924 199921 199910 199909 199905 199892 199892 199892 199888 199883 199882 199878 199877 199873 199872 199863 199859 199857 199855 199854 199853 199847 199844 199842 199838 199837 199833 199829 199828...
output:
0 683077295 122428774 2 -24298048 128227 937868532 424108432 303866944 -883269967 -719646861 262110842 -342029334 139146496 33866015 278478758 294879742 -440873497 945882552 -520414733 0 78963615 -423143954 -22832222 1 0 -937595413 672048473 319387351 -238034022 -1 0 -69424970 -339394007 1 911609054...
result:
Test #8:
score: 0
Time Limit Exceeded
input:
200000 199988 199987 199985 199978 199976 199974 199962 199962 199960 199952 199950 199949 199946 199938 199931 199927 199920 199917 199914 199909 199907 199905 199901 199900 199897 199890 199885 199871 199850 199842 199840 199835 199835 199831 199829 199819 199818 199810 199809 199808 199807 199806...
output:
237395027 -337419074 -189451091 1 -332788862 -1 91628900 -346043662 397302856 -722203477 -111751265 -659185879 45762 140456984 949846049 -379972995 -761374079 -332651862 989297551 -935292485 112011711 -873011453 -410823783 0 1 -865505400 -880351232 550473176 465331110 401963958 -357247174 251956197 ...
result:
Test #9:
score: 0
Time Limit Exceeded
input:
200000 199999 199999 199991 199990 199989 199986 199984 199983 199982 199981 199979 199977 199973 199973 199973 199972 199971 199969 199967 199964 199963 199962 199962 199961 199960 199959 199954 199953 199950 199950 199948 199947 199942 199938 199935 199934 199932 199931 199930 199925 199925 199922...
output:
-618058211 -734050272 1 -11203600 -336722737 -914687519 375284143 19237 1 -395141318 -69048 1 10236 0 87886 -19303 2 0 -2 -169171736 0 -1 -782437547 444544800 51067 -74335824 -70457261 85128948 -525514559 479010776 1 43759 -52350 33244 -9800 24695 1 0 -490716962 8958 0 -3693897 -25984536 0 -20124 0 ...
result:
Test #10:
score: 0
Time Limit Exceeded
input:
200000 200000 199996 199994 199993 199991 199990 199990 199989 199981 199980 199979 199977 199973 199971 199968 199967 199967 199964 199963 199960 199958 199958 199955 199947 199946 199945 199945 199945 199945 199943 199940 199940 199940 199938 199936 199935 199934 199932 199932 199930 199926 199925...
output:
-263580135 667701968 -11224 -1 -70891206 -1 1690 2 -61791271 -278009369 1 853497099 1 2 14719 -640923763 0 1 829743924 -688890570 -289895514 -601120093 1 -386308758 64450 -979451754 753881743 0 -5 1 -522553562 0 0 0 23469542 -1 331192702 -6273 803694403 -312676299 -255534346 1 -547768221 131496072 2...
result:
Test #11:
score: 0
Time Limit Exceeded
input:
200000 199999 199999 199998 199998 199996 199996 199996 199993 199991 199991 199990 199990 199986 199985 199984 199984 199982 199981 199981 199976 199970 199968 199966 199965 199962 199960 199960 199957 199952 199951 199950 199945 199944 199942 199942 199941 199940 199938 199938 199935 199935 199934...
output:
937427738 2 1 21738 2 784640227 459728606 396666044 -5 32972702 -136006731 3 -664847131 13572628 -1 952878858 -62169 147307138 79293988 444804441 -33190 -707856020 927532047 0 34736 1 -8970 533243010 -134524396 2 201976994 77884603 -82356160 -372290409 26427 -261006436 -431291287 4646 470509313 6045...
result:
Test #12:
score: 0
Time Limit Exceeded
input:
200000 199999 199998 199998 199996 199994 199994 199993 199988 199986 199985 199983 199981 199981 199979 199977 199975 199973 199972 199972 199971 199970 199970 199967 199961 199961 199955 199952 199950 199947 199946 199943 199940 199938 199937 199933 199933 199933 199931 199928 199919 199915 199915...
output:
22101 1 1 -86213 73537 -40151 -1 1 1 1 -67581 -211180674 878258016 1 0 123284856 17504 -496232527 -590405448 921105269 -951831643 0 -730770845 -668577548 -108260 -103047809 0 1 2 -14070 155098722 0 1 34392 148517696 -124869 1 17425 -965137204 995406597 -139176917 2 45653 -1 324278316 -1 329271818 65...
result:
Test #13:
score: 0
Time Limit Exceeded
input:
200000 199999 199999 199998 199998 199996 199996 199993 199992 199992 199992 199990 199989 199989 199989 199989 199988 199988 199986 199985 199982 199982 199981 199979 199978 199978 199978 199977 199977 199976 199975 199975 199972 199972 199971 199970 199969 199969 199967 199964 199964 199963 199963...
output:
0 1 -1 3 4039 -762313731 -128308 -62617 1 -88789 46236 98607 -225539293 2 13556 -66485 -73700 -8384 8625 -1 -1 30379 -9925 -113720 -239 11089 -813362156 9000 70878 86646 56527 -61538 1 -60132 -58243 -66809 -70998 -434646794 9160 -59127 -1 -47814 1 24923 -1 19784 -120409 4 -59636 16902732 -23172 1 17...
result:
Test #14:
score: 0
Time Limit Exceeded
input:
200000 199997 199993 199993 199993 199993 199992 199992 199991 199991 199990 199990 199990 199990 199986 199982 199982 199982 199980 199977 199977 199976 199974 199974 199974 199973 199973 199973 199971 199969 199968 199968 199966 199965 199965 199964 199963 199963 199962 199962 199962 199962 199961...
output:
0 -55940 1 69239 -36699 -89105 -64140 1 159261 1 60636 844737905 36872 0 13449 -4571 -1 -47211 -949 1 0 36123 -5115 -152890 -8943 -8313 45681237 0 0 -73976 -21301 -109017 206073603 1 -1 0 -30342 -495313695 1 -52 -74334 -134419 3 -38873 -130362 -8926 -43877 0 0 -846233453 -52 -90064 -43584 2 -53863 0...
result:
Test #15:
score: 0
Time Limit Exceeded
input:
200000 199996 199996 199995 199992 199991 199989 199988 199988 199986 199986 199985 199984 199983 199982 199982 199980 199978 199978 199973 199972 199971 199969 199969 199969 199969 199968 199968 199967 199967 199967 199967 199964 199961 199961 199960 199959 199959 199959 199958 199957 199956 199955...
output:
-59946 -114824 3656 0 63843 -40803 113453 3 1 -9890 -31946 0 0 -2 2 28995 0 -68641 -4 -1 0 61520 -27020 0 19327 162302 -122951 81442 -4201 16292 26195 46749 1 2 -35174 -107528 55201 108750 37007 2 0 0 -11268 87578 42309 43445 -29928 109883 48378 1 -929 40502 -51371 -42843 -108333 -7370 119592 50361 ...
result:
Test #16:
score: 0
Time Limit Exceeded
input:
200000 200000 199998 199996 199995 199993 199989 199988 199986 199985 199985 199985 199984 199979 199978 199977 199976 199974 199970 199969 199968 199968 199968 199966 199965 199964 199963 199963 199963 199961 199961 199961 199959 199959 199958 199958 199957 199956 199956 199955 199954 199954 199952...
output:
20228 -7356 1 11511 -3 2 30688 14136 -1 67270 27736 -2052 46897 37209 1 -11619 5898 -13750 47392 -3423 1 2 142316 92283 4 0 -1089 -2682 -66703 -621006111 -123578 7 -74253 -14566 -44362 80416 0 -9148 -2 0 71647 7594 -35771 0 -76794 -571 734634912 34301 18798 -50556 1451 -556165679 -21990 0 74475 0 -1...
result:
Test #17:
score: 0
Time Limit Exceeded
input:
200000 200000 200000 200000 200000 200000 200000 199998 199998 199998 199998 199996 199996 199996 199996 199996 199996 199994 199994 199994 199994 199992 199992 199992 199992 199992 199992 199990 199990 199990 199990 199990 199990 199988 199988 199988 199988 199986 199986 199986 199986 199984 199984...
output:
25728 -138377 161886 -138451 112828 -1 -118026 1 1 -117133 1 3342 97795 4797 1 -8564 -8987 1 34498 -100174 133383 100715 186477 126889 135751 -158957 -23614 127911 -31065561 1 122439 -1 4858 0 -148417 -165821 -1 138951 153129 -30321 -35278 169513 78435 -144990 -86108 -479774210 -1 -1895 42827 121289...
result:
Test #18:
score: 0
Time Limit Exceeded
input:
200000 200000 200000 200000 200000 199998 199998 199998 199998 199998 199998 199996 199996 199996 199996 199996 199996 199994 199994 199994 199994 199994 199994 199992 199992 199992 199992 199990 199990 199990 199990 199988 199988 199988 199988 199988 199988 199986 199986 199986 199986 199984 199984...
output:
-1 -34250 -73957 47388 10685 -33900 -151347 1 -4349 1 -15611 -100171 -1 -150845 -1 1 -121137 156682 104147 -63443 -128799 -128019 -155671 -166893 -141287 1 128537 -43126 535923341 80015 133545 1 -137261 1 129149 16186 1 -95455 166718 -122052 -24309 -1 74662 -148883 133071 149941 -182781 121585 1 695...
result:
Test #19:
score: 0
Time Limit Exceeded
input:
200000 199999 199998 199998 199997 199996 199996 199996 199996 199995 199995 199994 199994 199993 199990 199990 199989 199988 199986 199985 199985 199984 199984 199983 199980 199979 199979 199979 199979 199977 199977 199976 199976 199974 199973 199972 199971 199971 199970 199968 199966 199964 199960...
output:
13042 1 -946062094 -526108414 261673003 -134632 -97270890 578566247 -184259734 80162 -382956770 71197 1 -1 594690504 -1 0 0 -454244729 855885103 1 1 -25825 2 1 -1 -112685 -91050 240728375 -46755 -24651 -18243 -892814087 -1 -578524011 0 -417803356 -692062748 -194709572 0 -11985 2936 0 -383095986 0 81...
result:
Test #20:
score: 0
Time Limit Exceeded
input:
200000 199998 199995 199994 199993 199993 199992 199992 199991 199988 199986 199985 199985 199982 199981 199979 199978 199978 199977 199977 199977 199975 199975 199973 199971 199971 199970 199969 199968 199968 199967 199967 199963 199963 199962 199960 199959 199958 199958 199957 199956 199956 199954...
output:
4 189183586 1 603600219 46636 -37936 -3 -35830 1 2237 44288 3 -79069 2 -22585 -93025 16234 0 116969 1 1 36691 -22448 -142815 -36321 -3 52681 -25092 1 0 69920 -36746 1 -2 -72331 69637 15728 -44523 32809 23420 -96612 29114 6 20640 -1749 1 150011 1 -21267 30218 -1 -43035 -30668 -25871 108558009 -18684 ...
result:
Test #21:
score: 0
Time Limit Exceeded
input:
200000 200000 199999 199999 199998 199996 199995 199994 199994 199993 199991 199990 199989 199988 199988 199985 199985 199981 199980 199980 199980 199980 199979 199979 199978 199975 199973 199972 199970 199969 199969 199969 199968 199968 199966 199965 199965 199963 199961 199961 199961 199958 199958...
output:
-20767 -44908 -62039 44410 -74341 -148726 -1 0 79092 93315 1 55170 -55642 904 205181594 -61921 -23572 27191 -29390 7702 42551 24558 -54655 9619 -16770 1 10874 303934982 1 -25217 25016 31466 1 -54282 42636 -27157 -41207 -123353 -59740 20229 51254 5284 -5179 31845 -32963 1 -4195 24361 63554 1 19386744...
result:
Test #22:
score: 0
Time Limit Exceeded
input:
200000 200000 200000 199999 199997 199997 199996 199996 199995 199992 199991 199990 199989 199988 199988 199987 199987 199987 199986 199984 199984 199983 199982 199982 199982 199979 199979 199979 199974 199973 199972 199972 199970 199969 199969 199969 199967 199967 199965 199964 199961 199960 199956...
output:
0 -116822 139382 0 0 112646 1 18789 0 -17586 -65693 -64613 0 52679 20975 -91367 147879 -27515 1 -50542 -128991 0 -65794 0 1 1 1 -76775 -53483 1 268952 -42058 -141366 -102439 90387 0 131668 337 14265 -207903 -178023 50649 -37478 1 53006 76661 0 -77323 318746 1 1 0 67670 0 0 -99430 12828 0 0 131729 2 ...