QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202409 | #4429. Gebyte's Grind | Forever_Young | WA | 3212ms | 135688kb | C++23 | 2.9kb | 2023-10-06 01:12:06 | 2023-10-06 01:12:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n;i>=1;i--)
#define mp make_pair
#define pb push_back
#define N 2100000
const long long inf=2147483647ll*1000000000ll;
int n,q; long long h;
struct node
{
//if (0<=h<=x),f(h)=0
//if (x<h<=y), f(h)=p
//if (y<h), f(h)=h+q
long long x,y,p,q;
void print()
{
printf("x=%lld y=%lld p=%lld q=%lld\n",x,y,p,q);
}
void read()
{
char s[2]; long long w;
scanf("%s%lld",s,&w);
//puts(s); cout<<w<<endl;
if (s[0]=='B')
{
x=w; y=w; p=w; q=-w;
}
if (s[0]=='K')
{
x=w-1; y=inf; p=w; q=0;
}
if (s[0]=='C')
{
x=0; y=w; p=w; q=0;
}
}
long long eval(long long h)
{
if (h<=x)return 0;
if (h<=y)return p;
return h+q;
}
friend node operator +(node x,node y)
{
//y.eval(x.eval())
//if (0<=h<=x),f(h)=0
//if (x<h<=y), f(h)=p
//if (y<h), f(h)=h+q
node ret;
ret.x=x.x;
if (y.eval(x.p)==0)
{
ret.x=x.y;
//h+x.q<=y.x
ret.x=max(ret.x,y.x-x.q);
}
//ret.x=max(ret.x,-x.q-y.q);
ret.y=x.y;
//h+x.q<=y.y
ret.y=max(ret.y,y.y-x.q);
ret.p=y.eval(x.eval(ret.y));
ret.q=x.q+y.q;
return ret;
}
}st[4*N];
void build(int t,int l,int r)
{
if (l==r)
{
st[t].read();
//cout<<t<<" "; st[t].print();
return;
}
int mid=(l+r)/2;
build(2*t,l,mid);
build(2*t+1,mid+1,r);
st[t]=st[2*t]+st[2*t+1];
}
void modify(int t,int l,int r,int k)
{
if (l==r)
{
st[t].read();
return;
}
int mid=(l+r)/2;
if (k<=mid)modify(2*t,l,mid,k);
else modify(2*t+1,mid+1,r,k);
st[t]=st[2*t]+st[2*t+1];
}
node get(int t,int l,int r,int a,int b)
{
if (a<=l && r<=b)return st[t];
int mid=(l+r)/2;
if (b<=mid)return get(2*t,l,mid,a,b);
if (a>mid)return get(2*t+1,mid+1,r,a,b);
auto ret1=get(2*t,l,mid,a,b);
auto ret2=get(2*t+1,mid+1,r,a,b);
return ret1+ret2;
}
pair<int,long long> find(int t,int l,int r,int x,long long h)
{
if (x<=l)
{
if (st[t].eval(h)!=0)return mp(r,st[t].eval(h));
}
if (l==r)
{
return mp(l,st[t].eval(h));
}
int mid=(l+r)/2;
if (x>mid)return find(2*t+1,mid+1,r,x,h);
auto ret=find(2*t,l,mid,x,h);
if (ret.second==0)return ret;
return find(2*t+1,mid+1,r,mid+1,ret.second);
}
int main()
{
//freopen("1.in","r",stdin);
int T;
cin>>T;
while (T--)
{
scanf("%d%d%lld",&n,&q,&h);
build(1,1,n);
//auto ret1=get(1,1,n,1,2);
//auto ret2=get(1,1,n,3,3);
//auto ret3=ret1+ret2;
//ret1.print();
//ret2.print();
//ret3.print();
while (q--)
{
char s[2]; int x;
scanf("%s%d",s,&x);
if (s[0]=='Z') modify(1,1,n,x);
else
{
auto t=get(1,1,n,x,x);
if (t.eval(h)==0){ puts("-1"); continue; }
auto t1=get(1,1,n,x,n);
if (t1.eval(h)!=0){ printf("%d\n",n); continue; }
printf("%d\n",find(1,1,n,x,h).first-1);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3212ms
memory: 135688kb
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:
833302 238155 1007466 1912727 1483707 996123 913464 595444 1956432 168794 1224759 214012 1606540 541216 578117 1279590 1652446 647870 900696 1010723 1723225 1909185 765245 1770241 994028 135066 146309 423001 379625 188229 561102 1020950 25262 1007466 624537 1150303 892424 856521 175916 1187336 16896...
result:
ok 2911608 lines
Test #2:
score: -100
Wrong Answer
time: 2873ms
memory: 135028kb
input:
1 2000000 4000000 900000000000 B 18921988072 B 1 B 162148155907 C 1000000000000 B 331992393119 K 428836058413 B 440712983778 B 534362851268 B 923013640108 B 472973869469 B 21294011490 B 1 B 1000000000000 B 76485869786 C 1000000000000 C 333159763195 B 1 B 277856669933 B 1 C 445619227450 B 86360111824...
output:
1625020 1618321 511712 1446036 1302385 244605 534722 1807821 1673978 -1 -1 1286986 650766 1419851 -1 -1 510520 -1 1996906 814567 719623 1737532 180266 285086 -1 1455059 11094 1030136 1479157 372584 399911 1897918 1585202 566085 1522965 63081 1721860 673731 1530763 -1 -1 134340 1467445 -1 1410807 -1 ...
result:
wrong answer 27th lines differ - expected: '11092', found: '11094'