QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120879 | #6718. Масив i частковi суми | zhouhuanyi# | 31 | 5ms | 10204kb | C++11 | 2.1kb | 2023-07-07 12:08:07 | 2024-07-04 00:27:46 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 200000
using namespace std;
int read()
{
char c=0;
int sum=0,f=1;
while (c!='-'&&(c<'0'||c>'9')) c=getchar();
if (c=='-') c=getchar(),f=-1;
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum*f;
}
struct reads
{
int op,l,r;
};
reads tong[N+1];
int n,g,length;
long long a[N+1],maxn=(long long)(1e18);
__int128 s[N+1];
long long F(__int128 x)
{
if (x>maxn) x=maxn;
if (x<-maxn) x=-maxn;
return x;
}
void solve(int op,int l,int r)
{
if (op==1)
{
for (int i=1;i<=n;++i) a[i]=-a[i];
}
else if (op==2)
{
s[l]=a[l];
for (int i=l+1;i<=r;++i) s[i]=s[i-1]+a[i];
for (int i=l;i<=r;++i) a[i]=F(s[i]);
}
else
{
s[r]=a[r];
for (int i=r-1;i>=l;--i) s[i]=s[i+1]+a[i];
for (int i=l;i<=r;++i) a[i]=F(s[i]);
}
tong[++length]=(reads){op,l,r};
return;
}
int main()
{
int ps;
bool op;
n=read(),g=read();
for (int i=1;i<=n;++i) a[i]=read();
if (g==1)
{
op=1;
for (int i=1;i<=n;++i) op&=(a[i]>=0);
if (op) puts("0");
else
{
puts("1"),op=1;
for (int i=1;i<=n;++i) op&=(a[i]<=0);
if (op) puts("1");
else
{
for (int i=1;i<=n;++i) s[i]=s[i-1]+a[i];
op=1;
for (int i=1;i<=n;++i) op&=(s[i]>=0);
if (op) printf("2 %d %d\n",1,n);
else printf("3 %d %d\n",1,n);
}
}
}
else if (g==2)
{
ps=0;
for (int i=1;i<=n;++i)
if (abs(a[i])==1)
ps=i;
if (!ps) puts("0");
else
{
if (a[ps]<0) solve(1,0,0);
if (ps!=n)
{
solve(2,ps,ps+1);
solve(2,ps,ps+1);
for (int i=1;i<=40;++i) solve(2,ps,ps+1),solve(3,ps,ps+1);
}
else if (ps!=1)
{
solve(3,ps-1,ps);
solve(3,ps-1,ps);
for (int i=1;i<=40;++i) solve(2,ps-1,ps),solve(3,ps-1,ps);
}
solve(2,1,n),solve(3,1,n);
printf("%d\n",length);
for (int i=1;i<=length;++i)
{
if (tong[i].op==1) puts("1");
else printf("%d %d %d\n",tong[i].op,tong[i].l,tong[i].r);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 14
Accepted
Test #1:
score: 14
Accepted
time: 2ms
memory: 7728kb
input:
200000 1 1 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 0 0 1 1 0 1 0 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 0...
output:
0
result:
ok OK: 0 operations
Test #2:
score: 0
Accepted
time: 3ms
memory: 7632kb
input:
200000 1 -1 0 0 0 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 0 -1 -1 0 0 0 -1 -1 0 -1 0 -1 0 -1 0 -1 -1 0 0 -1 -1 0 0 -1 -1 0 -1 -1 -1 -1 0 -1 -1 0 0 0 -1 0 -1 -1 -1 0 -1 -1 0 0 0 -1 -1 -1 -1 -1 0 0 -1 -1 0 -1 0 -1 0 -1 -1 -1 0 -1 -1 0 0 0 0 -1 -1 -1 0 0 -1 -1 -1 0 0 -1 -1 -1 0 0 -1 -1 -1 0 -...
output:
1 1
result:
ok OK: 1 operations
Test #3:
score: 0
Accepted
time: 4ms
memory: 9716kb
input:
200000 1 0 0 1 -1 1 1 -1 -1 0 1 -1 0 0 1 0 0 1 1 1 1 0 -1 -1 0 -1 -1 1 -1 1 1 1 1 -1 1 -1 1 1 0 -1 -1 0 1 0 0 0 0 1 1 -1 0 0 -1 -1 -1 0 0 0 1 1 1 -1 1 1 0 0 1 1 -1 1 0 0 1 1 1 1 -1 0 1 0 0 0 0 1 0 0 -1 0 -1 1 -1 0 1 -1 -1 0 0 0 -1 0 0 1 1 1 0 -1 0 1 1 1 0 1 0 0 0 -1 -1 0 -1 -1 1 -1 -1 1 1 0 1 1 1 -1...
output:
1 2 1 200000
result:
ok OK: 1 operations
Test #4:
score: 0
Accepted
time: 4ms
memory: 9872kb
input:
200000 1 -1 -1 -1 -1 0 1 0 -1 -1 0 -1 -1 1 0 0 -1 0 1 -1 0 -1 1 -1 0 1 1 0 1 1 1 0 0 1 -1 0 1 0 0 0 0 1 1 1 1 1 0 1 -1 1 1 0 -1 0 1 0 0 0 1 1 0 1 0 -1 -1 0 0 -1 -1 0 1 -1 -1 -1 0 1 0 0 -1 0 1 0 1 1 1 1 0 1 -1 -1 -1 0 0 0 -1 1 1 -1 -1 -1 1 0 0 -1 -1 0 -1 -1 -1 0 1 1 1 1 0 1 -1 -1 0 -1 0 0 0 -1 -1 -1 ...
output:
1 3 1 200000
result:
ok OK: 1 operations
Subtask #2:
score: 17
Accepted
Test #5:
score: 17
Accepted
time: 3ms
memory: 8844kb
input:
200000 2 1 1 0 0 1 0 1 0 1 1 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0 1 1 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 1 1 0 0 0 1 1 0 1 0 1 0...
output:
84 2 199998 199999 2 199998 199999 2 199998 199999 3 199998 199999 2 199998 199999 3 199998 199999 2 199998 199999 3 199998 199999 2 199998 199999 3 199998 199999 2 199998 199999 3 199998 199999 2 199998 199999 3 199998 199999 2 199998 199999 3 199998 199999 2 199998 199999 3 199998 199999 2 199998 ...
result:
ok OK: 84 operations
Test #6:
score: 0
Accepted
time: 5ms
memory: 9952kb
input:
200000 2 0 0 -1 -1 0 -1 0 0 -1 -1 0 -1 -1 0 -1 0 -1 -1 -1 -1 -1 0 0 -1 0 -1 -1 0 0 -1 -1 -1 -1 -1 -1 -1 -1 0 0 -1 -1 0 -1 -1 -1 0 -1 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 -1 0 0 0 -1 -1 0 0 -1 -1 -1 0 -1 -1 0 -1 -1 -1 -1 0 -1 -1 -1 0 0 -1 0 0 0 -1 -1 -1 0 0 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 0 0 0 -1 -1...
output:
85 1 2 199999 200000 2 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 19999...
result:
ok OK: 85 operations
Test #7:
score: 0
Accepted
time: 0ms
memory: 9220kb
input:
200000 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
84 3 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 ...
result:
ok OK: 84 operations
Test #8:
score: 0
Accepted
time: 3ms
memory: 8564kb
input:
200000 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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:
84 3 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 ...
result:
ok OK: 84 operations
Test #9:
score: 0
Accepted
time: 0ms
memory: 8528kb
input:
200000 2 1 1 0 0 1 0 0 0 0 0 0 0 1 0 0 -1 0 0 0 0 -1 0 -1 0 -1 0 0 0 0 -1 0 0 0 -1 0 0 0 -1 0 -1 0 0 0 0 0 0 0 -1 -1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 -1 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 -1 0 0 0 1 0 0 -1 0 -1 0 0 0 0 0 -1 0 0 0 -1 -1 0 0 0 -1 0 -1 0 0 0 0 0 0 ...
output:
84 3 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 ...
result:
ok OK: 84 operations
Test #10:
score: 0
Accepted
time: 2ms
memory: 10204kb
input:
200000 2 -1 0 1 -1 0 1 1 0 1 0 0 1 0 1 -1 1 1 -1 1 -1 -1 0 -1 -1 0 -1 0 0 0 1 1 0 -1 1 -1 0 1 0 1 -1 -1 -1 -1 1 -1 1 1 -1 1 1 -1 0 1 -1 0 -1 1 -1 0 -1 1 -1 0 1 1 1 0 -1 0 -1 -1 -1 -1 0 0 -1 1 -1 -1 0 1 -1 0 0 0 0 0 0 1 1 1 0 -1 0 -1 1 -1 1 -1 1 1 0 0 1 1 -1 1 1 -1 -1 1 0 -1 1 -1 0 0 0 -1 0 0 1 1 -1 ...
output:
84 3 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 200000 3 199999 200000 2 199999 ...
result:
ok OK: 84 operations
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #11:
score: 0
Wrong Answer
time: 0ms
memory: 7584kb
input:
200000 3 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 1 0 0 0 0 1 1 0 0 1 0 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 0 1 0...
output:
result:
wrong output format Unexpected end of file - int32 expected
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 1ms
memory: 5672kb
input:
2891 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 ...
output:
result:
wrong output format Unexpected end of file - int32 expected
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%