QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#801697 | #9791. Intrusive Donkey | ucup-team1430# | RE | 0ms | 3792kb | C++20 | 3.0kb | 2024-12-07 05:38:55 | 2024-12-07 05:38:55 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define pb push_back
#define eb emplace_back
// #define debug(x) cout << #x << ": " << x << endl
#define debug(...)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define esp ' '
#define pii pair<int,int>
#define vi vector<int>
typedef long long ll;
const ll oo = 0x3f3f3f3f3f3f3f3f;
using namespace std;
struct SqrtDecomp {
using K = ll;
using T = ll;
int n, bsz, n_block;
vector<T> v;
vector<int> id;
vector<K> sum;
vector<K> lazy;
SqrtDecomp(int _n): n(_n), v(n, 1), id(n) {
bsz = sqrt(n) + 1;
n_block = (n + bsz -1) / bsz;
rep(i, 0, n) id[i] = i / bsz;
debug(bsz);
sum = vector<K>(n_block, 0);
lazy = vector<K>(n_block, 1);
rep(i, 0, n_block) prop(i);
}
void prop(int bid) {
rep(i, bid*bsz, min((bid+1) * bsz, n)) v[i] = v[i] * lazy[bid];
lazy[bid] = 1;
sum[bid] = 0;
rep(i, bid*bsz, min((bid+1) * bsz, n)) sum[bid] += v[i];
}
int query(ll idx) {
ll curr = 0;
// rep(i, 0, n_block) cout << sum[i] << " ";
// cout << endl;
// rep(i, 0, n) cout << v[i] << " ";
// cout << endl;
// cout << endl;
rep(bid, 0, n_block) if (curr + sum[bid] < idx) curr += sum[bid];
else{
prop(bid);
rep(i, bid*bsz, min((bid+1) * bsz, n)) if (curr + v[i] < idx) curr += v[i];
else return i;
}
return -1;
}
ll querysum(int l, int r) {
if (l > r) return 0;
ll ans = 0;
auto allblk = [&](int bid) {
ans += sum[bid];
};
auto sblk = [&](int bid, int flag) {
prop(bid);
rep(i, max(l, bid*bsz), min((bid+1)*bsz, r+1))
ans += v[i];
};
if (id[l] == id[r]) {
sblk(id[l], 2);
}
else {
sblk(id[l], 0);
rep(i, id[l]+1, id[r]) allblk(i); // blocos completos
sblk(id[r], 1);
}
return ans;
}
void update(ll l, ll r) {
int lx = query(l);
int rx = query(r);
auto allblk = [&](int bid) {
lazy[bid] *= 2;
sum[bid] *= 2;
};
ll sl = querysum(0, lx-1);
ll sr = querysum(0, rx-1);
rep(i, id[lx]+1, id[rx]) allblk(i); // blocos completos
if (id[lx] == id[rx]) {
prop(id[lx]);
rep(i, lx+1, rx) v[i] *= 2;
prop(id[lx]);
}
else {
prop(id[lx]);
prop(id[rx]);
rep(i, lx+1, min((id[lx]+1) * bsz, n)) v[i] *= 2;
rep(i, id[rx] * bsz, rx) v[i] *= 2;
prop(id[lx]);
prop(id[rx]);
}
debug(l);
debug(r);
debug(sl);
debug(sr);
debug(lx);
debug(rx);
if (lx == rx) {
v[lx] += rx-lx+1;
prop(id[lx]);
}
else {
ll manyl = v[lx] - (l - sl-1);
v[lx] += manyl;
ll manyr = (r - sr);
v[rx] += manyr;
prop(id[lx]);
prop(id[rx]);
}
}
};
void solve() {
int n, q;
cin >> n >> q;
string s; cin >> s;
SqrtDecomp decomp(sz(s));
while(q--) {
int t; cin >> t;
if (t == 2) {
ll x; cin >> x;
int idx = decomp.query(x);
assert(idx != -1);
cout << s[idx] << endl;
}
else if( t== 1) {
ll l, r;
cin >> l >> r;
decomp.update(l, r);
}
else assert(0);
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
//cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
4 7 abac 2 2 2 3 1 2 3 2 3 2 4 2 5 2 6
output:
b a b a a c
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
5 4 shrek 1 1 2 2 7 1 1 7 2 7
output:
k h
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
4 7 abac 2 2 2 3 1 2 3 2 3 2 4 2 5 2 6
output:
b a b a a c
result:
ok 6 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
5 4 shrek 1 1 2 2 7 1 1 7 2 7
output:
k h
result:
ok 2 lines
Test #5:
score: -100
Runtime Error
input:
3 55 vfe 1 2 3 1 2 2 1 3 5 2 4 1 1 2 2 9 2 7 2 5 1 10 10 1 1 1 2 9 1 8 12 2 8 1 7 10 2 1 1 5 6 1 1 4 1 20 24 1 14 32 1 19 38 2 48 1 56 64 2 58 2 19 1 64 72 1 36 86 2 11 1 117 124 2 38 2 108 2 85 1 112 118 2 153 2 40 2 114 2 80 1 11 18 2 27 2 73 1 159 162 2 84 1 130 164 2 163 2 65 1 150 156 1 101 109...