QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#260282 | #7627. Phony | ucup-team134# | WA | 1ms | 3620kb | C++14 | 2.2kb | 2023-11-21 23:42:10 | 2023-11-21 23:42:10 |
Judging History
answer
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
#define ll long long
const int N=500050;
ll a[N];
int main(){
int n,m;
ll k;
scanf("%i %i %lld",&n,&m,&k);
ordered_set<pair<ll,int>> all;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
all.insert({a[i],i});
}
ll a=all.rbegin()->first/k;
ll b=all.rbegin()->first%k;
if(b<0){
b+=k;
a--;
}
ll val=a;
ordered_set<pair<ll,int>> ost;
ost.insert({b, all.rbegin()->second});
all.erase(--all.end());
ll lzy=0;
while(all.size()){
ll a=all.rbegin()->first/k;
ll b=all.rbegin()->first%k;
if(b<0){
b+=k;
a--;
}
if(a==val){
ost.insert({b, all.rbegin()->second});
all.erase(--all.end());
}else{
break;
}
}
while(m--){
char c;
ll t;
scanf("\n%c %lld",&c,&t);
auto Get=[&](ll t){
ll ans;
if(t<=all.size()){
ans=all.find_by_order(t-1)->first;
}else{
t-=all.size();
ll add=val*k;
if(t<=lzy){
t+=(int)ost.size()-lzy;
add-=k;
}else{
t-=lzy;
}
ans=ost.find_by_order(t-1)->first+add;
}
return ans;
};
if(c=='A'){
t=n-t+1;
printf("%lld\n",Get(t));
}else{
while(t>0){
if(all.empty()){
lzy+=t;
val-=lzy/ost.size();
lzy%=ost.size();
break;
}
auto pos=*all.rbegin();
ll mx=pos.first;
ll a=mx/k;
ll b=mx%k;
if(b<0){
b+=k;
a--;
}
ll need=0;
auto it=ost.lower_bound({b,0});
if(it==ost.begin()){
need=ost.size()*(val-a)-lzy;
}else{
need=ost.size()*(val-a)-lzy-ost.order_of_key(*--it)-1;
}
ll use=min(need,t);
lzy+=use;
t-=use;
val-=lzy/k;
lzy%=k;
if(use==need){
//printf("[%lld %lld] add %lld\n",val*k, val*k+k-1,mx);
ost.insert({b,pos.second});
all.erase(--all.end());
lzy++;
}else{
break;
}
}
//for(int i=1;i<=n;i++){
// printf("%lld ",Get(i));
//}
//printf("\n");
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 1ms
memory: 3560kb
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 293 712 592 592
result:
wrong answer 2nd lines differ - expected: '200', found: '293'