QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744837 | #7627. Phony | Carucao | WA | 2ms | 16496kb | C++20 | 5.2kb | 2024-11-13 23:46:45 | 2024-11-13 23:46:45 |
Judging History
answer
#include<bits/stdc++.h>
#define ls i<<1
#define rs i<<1|1
#define fi first
#define se second
#define min amin
#define max amax
#define eb emplace_back
using namespace std;
using ll=long long;
using LL=__int128;
using pii=pair<int,int>;
const int N=5E5+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int p=998244353;
template<typename T=int>T read(){T x;cin>>x;return x;}
template<typename U,typename V>U min(const U &x,const V &y){return x<y?x:y;}
template<typename U,typename V>U max(const U &x,const V &y){return y<x?x:y;}
template<typename U,typename ...V>U min(const U &x,const V &...y){return min(x,min(y...));}
template<typename U,typename ...V>U max(const U &x,const V &...y){return max(x,max(y...));}
template<typename U,typename V>bool cmin(U &x,const V &y){return y<x?x=y,true:false;}
template<typename U,typename V>bool cmax(U &x,const V &y){return x<y?x=y,true:false;}
template<typename U,typename ...V>bool cmin(U &x,const V &...y){return cmin(x,min(y...));}
template<typename U,typename ...V>bool cmax(U &x,const V &...y){return cmax(x,max(y...));}
template<typename T>T qpow(T x,int n){T y=1;for(;n;n>>=1,x*=x)if(n&1)y*=x;return y;}
ll sqrt_floor(const ll &x){ll l=0,r=INT_MAX;while(l+1^r){ll mid=l+r>>1;(x<mid*mid?r:l)=mid;}return l;}
ll sqrt_ceil(const ll &x){ll l=-1,r=INT_MAX;while(l+1^r){ll mid=l+r>>1;(mid*mid<x?l:r)=mid;}return r;}
istream &operator>>(istream &is,LL &x){string a;is>>a;bool k=a[0]=='-';if(k)a=a.substr(1);x=0;for(char &t:a)x=x*10+t-48;if(k)x=-x;return is;}
ostream &operator<<(ostream &os,LL x){if(x<0)os<<'-',x=-x;string a;do a+=x%10|48;while(x/=10);reverse(a.begin(),a.end());return os<<a;}
mt19937 rng(time(0));
struct mint{
int x;
mint():x(){}
mint(const int &x):x(x<0?x+p:x){}
mint inv()const{return qpow(*this,p-2);}
mint operator-()const{return mint(x?p-x:x);}
mint &operator+=(const mint &t){return (x+=t.x)<p?0:x-=p,*this;}
mint &operator-=(const mint &t){return (x-=t.x)<0?x+=p:0,*this;}
mint &operator*=(const mint &t){return x=ll(x)*t.x%p,*this;}
mint &operator/=(const mint &t){return *this*=t.inv();}
mint operator+(const mint &t)const{return mint(*this)+=t;}
mint operator-(const mint &t)const{return mint(*this)-=t;}
mint operator*(const mint &t)const{return mint(*this)*=t;}
mint operator/(const mint &t)const{return mint(*this)/=t;}
friend mint operator+(const int &x,const mint &y){return mint(x)+=y;}
friend mint operator-(const int &x,const mint &y){return mint(x)-=y;}
friend mint operator*(const int &x,const mint &y){return mint(x)*=y;}
friend mint operator/(const int &x,const mint &y){return mint(x)/=y;}
friend istream &operator>>(istream &is,mint &t){return is>>t.x;}
friend ostream &operator<<(ostream &os,const mint &t){return os<<t.x;}
};
pair<ll,ll>a[N];
ll c[N];
int pre[N],rt[N],ch[N<<5][2],f[N<<5],cnt;
void ins(int u,int x){
++f[u];
for(int i=19;i--;){
int &v=ch[u][x>>i&1];
if(!v)v=++cnt;
++f[u=v];
}
}
int ask(int u,ll x){
int res=0;
for(int i=19;i--;){
ll t=x-f[ch[u][0]];
if(t>0){
u=ch[u][1];
res^=1<<i;
x=t;
}
else{
u=ch[u][0];
}
}
return res;
}
void mg(int &i,int j){
if(!j)return;
if(!i)i=j;
else{
f[i]+=f[j];
mg(ch[i][0],ch[j][0]);
mg(ch[i][1],ch[j][1]);
}
}
void split(int i,int &j,int k){
f[j=++cnt]=k;
f[i]-=k;
int t=k-f[ch[i][1]];
if(t<0){
split(ch[i][1],ch[j][1],k);
}
else{
ch[j][1]=ch[i][1];
ch[i][1]=0;
if(t)split(ch[i][0],ch[j][0],t);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
ll k;
cin>>n>>m>>k;
vector<ll>q;
for(int i=1;i<=n;++i){
cin>>a[i].fi;
q.eb(a[i].se=a[i].fi%k);
a[i].fi/=k;
}
sort(a+1,a+n+1);
sort(q.begin(),q.end());
q.erase(unique(q.begin(),q.end()),q.end());
a[0].fi=-1;
int s=0;
for(int i=1;i<=n;++i){
if(a[i].fi^a[i-1].fi){
rt[++s]=++cnt;
c[s]=a[i].fi;
pre[s]=pre[s-1];
}
ins(rt[s],lower_bound(q.begin(),q.end(),a[i].se)-q.begin());
++pre[s];
}
c[0]=-inf;
while(m--){
char C;
ll x;
cin>>C>>x;
if(C=='A'){
x=n-x+1;
int i=lower_bound(pre+1,pre+s+1,x)-pre;
cout<<c[i]*k+q[ask(rt[i],x-pre[i-1])]<<'\n';
}
else{
while(x/f[rt[s]]>=c[s]-c[s-1]){
x-=(c[s]-c[s-1])*f[rt[s]];
pre[--s]=n;
mg(rt[s],rt[s+1]);
}
ll t=x/f[rt[s]];
c[s]-=t;
x-=t*f[rt[s]];
if(!x)continue;
int u;
split(rt[s],u,x);
if(c[s]^c[s-1]+1){
rt[s+1]=rt[s];
c[s+1]=c[s];
pre[s+1]=n;
pre[s]-=f[rt[s]];
rt[s]=u;
--c[s];
}
else{
pre[s-1]+=f[u];
mg(rt[s-1],u);
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9852kb
input:
3 5 5 7 3 9 A 3 C 1 A 2 C 2 A 3
output:
3 4 -1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 16496kb
input:
5 8 8 294 928 293 392 719 A 4 C 200 A 5 C 10 A 2 C 120 A 1 A 3
output:
294 200 189 190 184
result:
wrong answer 3rd lines differ - expected: '191', found: '189'