QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#108700 | #4429. Gebyte's Grind | lmeowdn | RE | 0ms | 0kb | C++17 | 2.9kb | 2023-05-26 12:31:31 | 2023-05-26 12:31:33 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
#define clz __builtin_clz
#define ctz __builtin_ctz
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef long double ld;
typedef unsigned long long ull;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
int readop() {
static char s[19]; scanf("%s",s);
if(s[0]=='B') return 1;
else if(s[0]=='K') return 2;
else if(s[0]=='C') return 3;
else if(s[0]=='Z') return 1;
else if(s[0]=='D') return 2;
else return assert(0), 0;
}
const int N=1e6+9,inf=2e18;
int n,q,H,ls[N<<1],rs[N<<1],tot=1,tmp[N],cnt,xl[N<<1],xr[N<<1];
struct info {int a,p,q;} a[N],s[N<<1];
info trans(int op,int a) {
if(op==1) return (info){1,a+1,a+1};
else if(op==2) return (info){a,a,inf};
else return (info){a,1,a};
}
info operator + (const info &x,const info &y) {
info z;
if(y.p-x.a<=0) z.p=x.p;
else z.p=y.p-x.a+x.q;
if(x.a-y.q<0) z.a=y.a, z.q=x.q-x.a+y.q;
else z.a=y.a+x.a-y.q, z.q=x.q;
if(z.a>inf) z.a=inf;
if(z.p>inf) z.p=inf;
if(z.q>inf) z.q=inf;
return z;
}
void build(int p,int l,int r) {
xl[p]=l, xr[p]=r;
if(l==r) {s[p]=a[l]; return;} int mid=l+r>>1;
build(ls[p]=++tot,l,mid), build(rs[p]=++tot,mid+1,r);
s[p]=s[ls[p]]+s[rs[p]];
}
void mdf(int p,int l,int r,int x) {
if(l==r) {s[p]=a[l]; return;} int mid=l+r>>1;
if(x<=mid) mdf(ls[p],l,mid,x); else mdf(rs[p],mid+1,r,x);
s[p]=s[ls[p]]+s[rs[p]];
}
void find(int p,int l,int r,int x,int y) {
if(l==x&&r==y) {tmp[++cnt]=p; return;}
int mid=l+r>>1;
if(y<=mid) find(ls[p],l,mid,x,mid);
else if(x>mid) find(rs[p],mid+1,r,x,y);
else find(ls[p],l,mid,x,mid),find(rs[p],mid+1,r,mid+1,y);
}
int qry(int p,int l,int r,info f) {
if(l==r) return l-1;
info g=f+s[ls[p]]; int mid=l+r>>1;
if(g.p>H) return qry(ls[p],l,mid,f);
else return qry(rs[p],mid+1,r,g);
}
int query(int l) {
cnt=0; find(1,1,n,l,n); info f=(info){0,0,0};
rep(i,1,cnt) {
int p=tmp[i]; info g=f+s[p];
if(g.p>H) return qry(p,xl[p],xr[p],f);
else f=g;
}
return n;
}
signed main() {
for(int T=read();T;T--) {
n=read(), q=read(), H=read();
rep(i,1,tot) s[i]=(info){0,0,0}, ls[i]=rs[i]=0; tot=1;
rep(i,1,n) {
int op=readop(), x=read();
a[i]=trans(op,x);
}
build(1,1,n);
rep(i,1,q) {
int opt=readop();
if(opt==1) {
int pos=read(), op=readop(), x=read();
a[pos]=trans(op,x);
mdf(1,1,n,pos);
} else {
int pos=read();
if(a[pos].p>H) puts("-1");
else printf("%lld\n",query(pos));
}
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
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...