QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#394913 | #8540. Splitting Haybales | tx344 | 100 ✓ | 1253ms | 85248kb | C++14 | 3.2kb | 2024-04-20 21:41:13 | 2024-04-20 21:41:14 |
Judging History
answer
//
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5,V=2e5,B=2048;
int n,a[N],Q,be[N],ti;
void f(int &x,int y){x=x>0?x-y:x+y;}
struct Blocks
{
int L,R,trans[N];
ll sum;
void Build(int vl,int vr,int now)
{
// if(++ti<10000)printf("%-8d %-8d %-8d\n",vl,vr,now);
if(now>R)
{
// printf("trans:%d %d %d %d\n",L,R,vl,vr);
int x=0;
if(vl<=vr)for(int i=vl;i<=vr;i++)trans[i]=++x;
else for(int i=vl;i>=vr;i--)trans[i]=x--;
return;
}
int w=a[now];
// printf("%d %d %d %d\n",vl,vr,now,w);
if(vl<=vr)
{
if(2*w<=vr-vl+1)
{
Build(vl+w,vr,now+1);
for(int i=vl+w-1,j=vl+w;i>=vl;i--,j++)
{
if(i<=0)printf("ERR:%d\n",i);
trans[i]=1-trans[j];
}
}
else
{
Build(vl+w-1,vl,now+1);
for(int i=vl+w,j=vl+w-1;i<=vr;i++,j--)
{
if(j<=0)printf("ERR:%d\n",j);
trans[i]=1-trans[j];
}
}
}
else
{
if(2*w<=vl-vr+1)
{
Build(vl-w,vr,now+1);
for(int i=vl-w+1,j=vl-w;i<=vl;i++,j--)
{
if(j<=0)printf("ERR:%d\n",j);
trans[i]=1-trans[j];
}
}
else
{
Build(vl-w+1,vl,now+1);
for(int i=vl-w,j=vl-w+1;i>=vr;i--,j++)
{
if(i<=0)printf("ERR:%d\n",i);
trans[i]=1-trans[j];
}
}
}
}
void Print()
{
printf("%d %d\n",L,R);
for(int i=1;i<=100;i++)printf("%d ",trans[i]);puts("");
}
}bl[N/B+5];
int main()
{
#ifndef ONLINE_JUDGE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]),be[i]=(i-1)/B+1,bl[be[i]].sum+=a[i];
for(int i=1;i<=be[n];i++)
{
// printf("R:%d %d\n",i,bl[i].R);
bl[i].L=bl[i-1].R+1;
bl[i].R=min(i*B,n);
bl[i].Build(1,V,bl[i].L);
// bl[i].Print();
}
cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
scanf("%d",&Q);
while(Q--)
{
int l,r,x;
scanf("%d%d%d",&l,&r,&x);
while(l<=r&&l!=bl[be[l]].L)f(x,a[l++]);
while(l<=r&&be[l]!=be[r]&&((x>V&&x-bl[be[l]].sum>V)||(x<=-V&&x+bl[be[l]].sum<=-V)))f(x,bl[be[l]].sum),l+=B;
// printf(" %d %d %d\n",l,r,x);
if(l<=r)f(x,a[l++]);
while(l<=r&&l!=bl[be[l]].L)f(x,a[l++]);
// printf(" 1:%d %d %d\n",l,r,x);
while(l<=r&&be[l]<be[r])
{
// printf("%d %d %d %d\n",bl[be[l]].L,bl[be[l]].R,x,be[l]);
// if(x>0)printf("%d ",bl[be[l]].trans[x]);
// else printf("%d ",1-bl[be[l]].trans[1-x]);
x=x>0?bl[be[l]].trans[x]:1-bl[be[l]].trans[1-x],l+=B;
}
// puts("");
while(l<=r)f(x,a[l++]);
printf("%d\n",x);
}
cerr<<bl[45].trans[88]<<'\n';
cerr<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.54545
Accepted
time: 1ms
memory: 4860kb
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: 1ms
memory: 8476kb
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: 4.54545
Accepted
time: 24ms
memory: 84676kb
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 63655 -152199 -102062 -1 -12287 -26123 -94203962 26393 0 36993 93272 -44019 1 -13074 -75312 -33791 -23354 -1 2 -76892 1711 111108 338346276 -1 -22116 2 27682 10079 -19145 -2227 35136 -1 -72252 -71143 -96720663 1 -26095472 -4030 1 -11544 0 111439361 -37352 -1362 -72042 -37209 42334 -73...
result:
ok 100 lines
Test #4:
score: 4.54545
Accepted
time: 1253ms
memory: 84800kb
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:
ok 200000 lines
Test #5:
score: 4.54545
Accepted
time: 1246ms
memory: 84684kb
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:
ok 200000 lines
Test #6:
score: 4.54545
Accepted
time: 1064ms
memory: 85204kb
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 -106477 0 -154442 0 -148812 184...
result:
ok 200000 lines
Test #7:
score: 4.54545
Accepted
time: 616ms
memory: 85248kb
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 128377 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:
ok 200000 lines
Test #8:
score: 4.54545
Accepted
time: 625ms
memory: 84696kb
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:
ok 200000 lines
Test #9:
score: 4.54545
Accepted
time: 846ms
memory: 84684kb
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 19543 1 -395141318 -69048 1 10434 0 87990 -19303 2 0 -2 -169171736 0 -1 -782437547 444544800 51405 -74335824 -70457261 85128948 -525514559 479010776 1 43759 -52350 33244 -9362 24695 1 0 -490716962 8958 0 -3693897 -25984536 0 -19874 0 ...
result:
ok 200000 lines
Test #10:
score: 4.54545
Accepted
time: 849ms
memory: 84672kb
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 15083 -640923763 0 1 829743924 -688890570 -289895514 -601120093 1 -386308758 64546 -979451754 753881743 0 -5 1 -522553562 0 0 0 23469542 -1 331192702 -6273 803694403 -312676299 -255534346 1 -547768221 131496072 2...
result:
ok 200000 lines
Test #11:
score: 4.54545
Accepted
time: 869ms
memory: 84680kb
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 34786 1 -8970 533243010 -134524396 2 201976994 77884603 -82356160 -372290409 26661 -261006436 -431291287 4646 470509313 6045...
result:
ok 200000 lines
Test #12:
score: 4.54545
Accepted
time: 846ms
memory: 85228kb
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 -86131 73643 -40151 -1 1 1 1 -67581 -211180674 878258016 1 0 123284856 17602 -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:
ok 200000 lines
Test #13:
score: 4.54545
Accepted
time: 1194ms
memory: 82512kb
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 46416 98607 -225539293 2 13556 -66485 -73356 -8384 8759 -1 -1 30419 -9911 -113634 -1 11401 -813362156 9000 70878 86646 56633 -61538 1 -60132 -57849 -66703 -70998 -434646794 9160 -59127 -1 -47624 1 24923 -1 19784 -120409 4 -59548 16902732 -23172 1 1745...
result:
ok 200000 lines
Test #14:
score: 4.54545
Accepted
time: 1162ms
memory: 84252kb
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 -55846 1 69239 -36699 -89105 -64140 1 159285 1 60636 844737905 37010 0 13449 -4421 -1 -47211 -949 1 0 36123 -5115 -152828 -8943 -8313 45681237 0 0 -73778 -21301 -108731 206073603 1 -1 0 -30342 -495313695 1 -52 -74334 -134419 3 -38873 -130330 -8926 -43877 0 0 -846233453 -52 -89790 -43584 2 -53863 0...
result:
ok 200000 lines
Test #15:
score: 4.54545
Accepted
time: 1178ms
memory: 84336kb
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 3816 0 63907 -40803 113641 3 1 -9890 -31946 0 0 -2 2 29249 0 -68641 -4 -1 0 61574 -27020 0 19327 162384 -122833 81442 -4201 16292 26355 46749 1 2 -35174 -107528 55201 108750 37007 2 0 0 -11268 87578 42309 43487 -29928 109883 48378 1 -929 40502 -51047 -42843 -108333 -7190 119592 50361 ...
result:
ok 200000 lines
Test #16:
score: 4.54545
Accepted
time: 1160ms
memory: 84680kb
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:
20400 -7316 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 -2564 -66703 -621006111 -123458 7 -74253 -14566 -43746 80416 0 -9148 -2 0 71651 7594 -35355 0 -76794 -571 734634912 34301 18798 -50556 1451 -556165679 -21990 0 74475 0 -1...
result:
ok 200000 lines
Test #17:
score: 4.54545
Accepted
time: 1098ms
memory: 84944kb
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:
ok 200000 lines
Test #18:
score: 4.54545
Accepted
time: 1091ms
memory: 84696kb
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:
ok 200000 lines
Test #19:
score: 4.54545
Accepted
time: 1013ms
memory: 84792kb
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:
13228 1 -946062094 -526108414 261673003 -134632 -97270890 578566247 -184259734 80162 -382956770 71367 1 -1 594690504 -1 0 0 -454244729 855885103 1 1 -25825 2 1 -1 -112685 -91050 240728375 -46675 -24651 -18243 -892814087 -1 -578524011 0 -417803356 -692062748 -194709572 0 -11985 3012 0 -383095986 0 81...
result:
ok 200000 lines
Test #20:
score: 4.54545
Accepted
time: 1209ms
memory: 84264kb
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 46878 -37532 -3 -35830 1 2443 44288 3 -79069 2 -22585 -93025 16234 0 116969 1 1 36691 -22150 -142815 -36321 -3 52681 -25092 1 0 69920 -36746 1 -2 -72231 69663 15728 -44523 32809 23420 -96612 29184 6 20640 -1749 1 150035 1 -21267 30218 -1 -42995 -30512 -25871 108558009 -18684 ...
result:
ok 200000 lines
Test #21:
score: 4.54545
Accepted
time: 1204ms
memory: 85224kb
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 44636 -74031 -148726 -1 0 79092 93315 1 55170 -55642 956 205181594 -61921 -23512 27333 -29390 7702 42787 24834 -54655 10101 -16770 1 10874 303934982 1 -25175 25016 31466 1 -54282 43172 -27157 -41207 -123353 -59740 20339 51254 5402 -4573 31845 -32963 1 -4195 24361 63852 1 1938674...
result:
ok 200000 lines
Test #22:
score: 4.54545
Accepted
time: 1172ms
memory: 84676kb
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 -116796 139394 0 0 112646 1 18789 0 -17056 -65305 -64209 0 52679 20975 -91367 147879 -27255 1 -50166 -128771 0 -65388 0 1 1 1 -76751 -53483 1 268952 -42058 -141322 -102385 90387 0 131668 337 14265 -207903 -178023 50649 -37056 1 53006 76661 0 -77029 318746 1 1 0 67670 0 0 -99430 12828 0 0 131729 2 ...
result:
ok 200000 lines