QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#385925 | #8540. Splitting Haybales | cqbzdj | 13.636364 | 603ms | 12640kb | C++14 | 3.5kb | 2024-04-11 10:09:08 | 2024-04-11 10:09:09 |
Judging History
answer
//
#include <bits/stdc++.h>
#define LL long long
#define mes(s, x) memset(s, x, sizeof(s))
#define Maxn 200005
#define Maxb 500
using namespace std;
inline LL read(){char c;c = getchar();while(!(('0' <= c && c <= '9') || c == '-')) c = getchar();bool flag = 0;if(c == '-'){flag = 1;c = getchar();}LL tot = 0;while('0' <= c && c <= '9'){tot = 10 * tot + c - '0';c = getchar();}return flag ? -tot : tot;}
struct query{
int r, x, id;
};
vector<query> q[Maxb], nq;
int a[Maxn], ans[Maxn], f[2 * Maxn];
int find(int i){
if(i == f[i]) return i;
return f[i] = find(f[i]);
}
void merge(int i, int j){
i = find(i), j = find(j);
f[i] = j;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int n = read(), m, blk, x, y, z, s, k, tl;
blk = sqrt(n) + 0.5;
for(int i = 1; i <= n; i++) a[i] = read();
m = read();
for(int i = 1; i <= m; i++){
x = read(), y = read(), z = read();
if((x - 1) / blk == (y - 1) / blk){
for(int j = x; j <= y; j++) z += (z <= 0 ? a[j] : -a[j]);
ans[i] = z;
}else{
for(int j = x; j <= ((x - 1) / blk + 1) * blk; j++) z += (z <= 0 ? a[j] : -a[j]);
q[(x - 1) / blk + 2].push_back({y, z, i});
}
}
for(int i = 1, l, r; (i - 1) * blk < n; i++){
l = (i - 1) * blk + 1, r = min(i * blk, n);
for(int j = 0; j <= 400000; j++) f[j] = j;
s = 0, z = 0, x = 1, y = 200000 - 1, k = 1;
for(int j = l; j <= r; j++){
s += a[j];
z += (z <= 0 ? a[j] : -a[j]);
k += (2 * k + l <= 0 ? a[j] : -a[j]);
if(k < 0 && k + y > 0){
if(-k > k + y){
for(int o = 1; o <= k + y; o++){
merge(x - k + o + 200000, -(x - k - o) + 200000);
merge(-(x - k + o) + 200000, x - k - o + 200000);
}
y = -k;
}else{
for(int o = k; o < 0; o++){
merge(x - k + o + 200000, -(x - k - o) + 200000);
merge(-(x - k + o) + 200000, x - k - o + 200000);
}
x = x - k;
y = y + k;
k = 0;
}
}
}
for(int j = 0; j < q[i].size(); j++){
if(q[i][j].r <= r){
tl = q[i][j].x;
for(int o = l; o <= q[i][j].r; o++) tl += (tl <= 0 ? a[o] : -a[o]);
ans[q[i][j].id] = tl;
}else{
if(abs(q[i][j].x) > 200000){
if(abs(q[i][j].x) >= s) q[i][j].x += (q[i][j].x > 0 ? -s : s);
else{
tl = q[i][j].x;
for(int o = l; o <= q[i][j].r; o++) tl += (tl <= 0 ? a[o] : -a[o]);
q[i][j].x = tl;
}
}else if(q[i][j].x == 0){
q[i][j].x = z;
}else{
tl = find(q[i][j].x + 200000) - 200000;
if(tl > 0) tl = tl - x + k;
else tl = -(-tl - x + k);
q[i][j].x = tl;
}
q[i + 1].push_back(q[i][j]);
}
}
q[i].clear();
q[i].shrink_to_fit();
}
for(int i = 1; i <= m; i++) printf("%d\n", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4.54545
Accepted
time: 1ms
memory: 5444kb
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: 6684kb
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
Wrong Answer
time: 119ms
memory: 6284kb
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:
29851 5578 109531 54147 -146861 -90713 -2 118957 104255 -94203962 24953 0 648 -44451 17108 -57136 -5461 -40513 -2019 225 -7753 4864 -76847 -672 97541 338346276 1112 21922 2 -153261 0 0 -104921 16028 249 -23978 -28567 -96720663 -919 -26095472 -739 2202 -3346 1 111439361 -36517 75782 -45717 0 -41969 2...
result:
wrong answer 1st lines differ - expected: '-42604', found: '29851'
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:
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:
result:
Test #6:
score: 4.54545
Accepted
time: 603ms
memory: 12640kb
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: 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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
result:
Test #22:
score: 0
Wrong Answer
time: 600ms
memory: 12620kb
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:
wrong answer 127th lines differ - expected: '-38732', found: '38732'