QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#42868 | #4429. Gebyte's Grind | fecto_elfilis | WA | 4373ms | 191208kb | C++ | 2.4kb | 2022-08-04 16:04:33 | 2022-08-04 16:04:36 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2000010;
int cntt;
struct P {
ll a,b,v;
P (ll x=0,ll y=0) {
if (x==0) {a=b=v=0;}
else if (x==1) {a=b=y,v=0;}
else if (x==2) {a=y-1,v=y,b=1e18;}
else if (x==3) {a=0,b=v=y;}
}
}seg[N*4];
P operator + (P a,P b) {
P c;
if (a.v<=b.a) {
c.a=a.b+b.a-a.v;
c.b=c.a+b.b-b.a;
c.v=b.v;
} else {
c.a=a.a;
if (a.v<=b.b) {
c.b=a.b+b.b-a.v;
c.v=b.v;
} else {
c.b=a.b;
c.v=b.v+a.v-b.b;
}
}
return c;
}
ll read () {
ll res=0;
char c=getchar();
while (c<'0'||c>'9') {c=getchar();}
while (c>='0'&&c<='9') {
res=res*10-'0'+c;
c=getchar();
}
return res;
}
void write (ll x) {
if (x<=9) {putchar(x+'0');return;}
write(x/10);
putchar(x%10+'0');
}
ll t,n,q,h,x,y;
char s[10];
void buildt (int p,int l,int r) {
seg[p]=P();
if (l==r) {return;}
int mid=(l+r)>>1;
buildt(p<<1,l,mid),buildt((p<<1)|1,mid+1,r);
}
void modify (int p,int l,int r,int pos,P v) {
if (l==r) {seg[p]=v;return;}
int mid=(l+r)>>1;
if (pos<=mid) {modify(p<<1,l,mid,pos,v);}
else {modify((p<<1)|1,mid+1,r,pos,v);}
seg[p]=seg[p<<1]+seg[(p<<1)|1];
}
pair<ll,P> query (int p,int l,int r,int x,P nw) {
if (l==r) {
if ((nw+seg[p]).a>=h) {return make_pair(l-1,nw);}
else {return make_pair(l,nw+seg[p]);}
}
int mid=(l+r)>>1;
if (x>mid) {return query((p<<1)|1,mid+1,r,x,nw);}
else {
pair<ll,P> tmp=query(p<<1,l,mid,x,nw);
if (cntt==10) printf("%d %d %d %d %lld %lld %lld %lld\n",p,l,mid,r,tmp.first,
tmp.second.a,tmp.second.b,tmp.second.v);
if (tmp.first<mid) {return tmp;}
P tmpp=tmp.second+seg[(p<<1)|1];
if (tmpp.a>=h) {return query((p<<1)|1,mid+1,r,x,tmp.second);}
else {return make_pair(r,tmpp);}
}
}
int main () {
t=read();
for (int ii=1;ii<=t;ii++) {
n=read();q=read(),h=read();
buildt(1,1,n);
for (int i=1;i<=n;i++) {
scanf("%s",s+1);
x=read();
modify(1,1,n,i,P(s[1]=='B'?1:(s[1]=='K'?2:3),x));
}
for (int i=1;i<=q;i++) {
scanf("%s",s+1);
x=read();
if (s[1]=='Z') {
scanf("%s",s+1);
y=read();
modify(1,1,n,x,P(s[1]=='B'?1:(s[1]=='K'?2:3),y));
} else {
cntt++;
ll res=query(1,1,n,x,P()).first;
continue;
if (res<x) {
putchar('-');
putchar('1');
putchar('\n');
} else {write(res);putchar('\n');}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4373ms
memory: 191208kb
input:
1 2000000 4000000 1000000000000 B 2982992025 B 1226542907 B 2299259203 B 1223702056 B 1407121251 B 340783317 B 1259091208 B 2101980047 B 2611543443 B 2010658889 B 4233714406 B 3112120167 B 2311876255 B 2789960428 B 3008572010 B 1 B 2464951378 B 1364240867 B 2829584762 B 2511437438 B 692948679 B 1113...
output:
1134033 162999 162999 163000 162999 1800657353 1800657353 0 283508 162997 163000 163004 163000 3823310308 3823310308 0 141754 162997 163004 163011 163004 3823310308 1003823310308 995854316920 70877 162997 163011 163026 163011 3823310308 1003823310308 984234422...
result:
wrong answer 1st lines differ - expected: '833302', found: '1134033 162999 162999 1630...999 1800657353 1800657353 0'