QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667264 | #7627. Phony | MiniLong | WA | 1ms | 3856kb | C++14 | 4.0kb | 2024-10-22 21:57:41 | 2024-10-22 21:57:51 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<ll, ll> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 5e5 + 5;
ll n, m, k, pos, t, tag, cur, a[N];
set<PII> st;
ll lst, now;
ll ask(ll k){//第k小的数
auto it = st.begin();
_rep(i, 1, k - 1) it = next(it);
return (*it).fi;
}
void update(ll t){
ll len = n - pos + 1;
if(t >= now){
t -= now, now = 0, lst = (*st.begin()).fi - tag * k;
while(t > 0 && pos > 1){
if(lst < a[pos - 1]){
st.insert({a[pos - 1] + tag * k, pos - 1});
pos--, len++;
continue;
}
ll o = ((lst - a[pos - 1]) / k + 1) * len;
if(o > t) break;
tag += ((lst - a[pos - 1]) / k + 1);
st.insert({a[pos - 1] + tag * k, pos - 1});
t -= o;
pos--, len++;
}
if(pos == 1){
tag += t / n; t %= n;
lst = (*st.begin()).fi - tag * k;
}
}
if(t){
if(!now) tag++, now = len - t;
else now -= t;
lst = ask(now + 1) - tag * k;
while(pos > 1 && a[pos - 1] > lst) st.insert({a[pos - 1] + tag * k, pos - 1}), pos--, len++;
}
}
ll getrk(ll rk){
ll len = n - pos + 1;
if(rk > len) return a[pos - (rk - len)];
if(rk <= now) return ask(now - rk + 1) - (tag - 1) * k;
ll t = rk - now;
t = len - t + 1;
return ask(t) - tag * k;
}
int main(){
read(n, m, k);
_rep(i, 1, n) read(a[i]);
sort(a + 1, a + 1 + n);
st.insert({a[n], n}), pos = n;
// debug("eee\n");
while(m--){
char ch[2]; ll x;
scanf("%s", ch);
// debug("eee\n");
read(x);
if(ch[0] == 'C'){
update(x);
}
if(ch[0] == 'A'){
writeln(getrk(x));
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3836kb
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: 3856kb
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 160 312 -96 30
result:
wrong answer 2nd lines differ - expected: '200', found: '160'