QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#219060 | #7627. Phony | PhantomThreshold# | WA | 1ms | 3556kb | C++20 | 2.4kb | 2023-10-18 23:20:42 | 2023-10-18 23:20:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef long long ll;
tree<pair<ll,int>,null_type,less<pair<ll,int>>,rb_tree_tag,tree_order_statistics_node_update> rb;
auto kth(int x)
{
return *rb.find_by_order(x-1);
}
auto rnk(ll x)
{
return rb.order_of_key(make_pair(x,0))+1;
}
int main()
{
ios_base::sync_with_stdio(false);
int n,m;
long long k;
cin>>n>>m>>k;
vector<ll> a(n+5);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a.begin()+1,a.begin()+n+1);
rb.insert(make_pair(a[n]%k,n));
ll nowq=a[n]/k;
int now=n-1;
int sub=0;
for(int i=1;i<=m;i++)
{
char ty;
long long t;
cin>>ty>>t;
if(ty=='C')
{
// cerr<<"change* "<<t<<endl;
while(t)
{
ll nxq=a[now]/k;
if(now==0)nxq=-1e18;
// cerr<<"nxq "<<nxq<<", nowq "<<nowq<<' '<<rnk(a[now]%k)<<' '<<n-now-sub+1<<endl;
if(nxq==nowq-1 and rnk(a[now]%k)==n-now-sub+1)
{
rb.insert(make_pair(a[now]%k,now));
now--;
sub++;
continue;
}
if(nowq!=nxq)
{
int lim=n-now-sub;
if(t<lim)
{
sub+=t,t=0;
// cerr<<"sub "<<sub<<endl;
}
else
{
t-=lim,sub=0,nowq--;
// cerr<<"new nowq "<<nowq<<endl;
}
continue;
}
// cerr<<"phase 1 t="<<t<<endl;
ll fulllim=min(nowq-nxq,t/(n-now));
// cerr<<"all-= "<<fulllim<<endl;
t-=fulllim*(n-now);
nowq-=fulllim;
// cerr<<"phase 2 t="<<t<<endl;
if(fulllim)continue;
int lim=n-now-sub-rnk(a[now]%k)+1;
// cerr<<"lim2 "<<lim<<endl;
if(lim<=t)
{
sub+=lim;t-=lim;
// cerr<<"new sub "<<sub<<endl;
// cerr<<"insert "<<a[now]%k<<endl;
rb.insert(make_pair(a[now]%k,now));
// sub++;
now--;
}
else
{
sub+=t;t=0;
// cerr<<"new sub "<<sub<<endl;
}
if(sub==n-now)
{
// cerr<<"clear sub"<<endl;
sub=0,nowq--;
}
// cerr<<"phase 3 t="<<t<<endl;
}
}
else
{
t=n+1-t;
// cerr<<kth(1).first<<' '<<kth(2).first<<' '<<kth(3).first<<endl;
// cerr<<nowq<<' '<<sub<<endl;
if(t<=now)cout<<a[t]<<"\n";
else
{
t-=now;
if(t<=sub)
{
cout<<kth(t+(n-now-sub)).first+(nowq-1)*k<<"\n";
}
else
{
t-=sub;
cout<<kth(t).first+nowq*k<<"\n";
}
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3408kb
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: 0
Accepted
time: 1ms
memory: 3556kb
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 191 0 -2
result:
ok 5 lines
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3528kb
input:
100 100 233 5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...
output:
6881 9161 4721 8200 2945 7647 7530 5291 5001 2042 4721 4721 6881 4097 7181 7218 7018 7018 811 6742 2561 6683 6103 6135 3581 5291 1485 5957 5393 2042 5303 5171 5205 4721 5084 4029 4097 4586 4816 4721 4698 2042 4535 4454 4603 4422 3581 4345 115 2042 4274 2042 4273 1485 4326 -17552
result:
wrong answer 7th lines differ - expected: '7531', found: '7530'