QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#781144 | #9791. Intrusive Donkey | GenshinImpactShutdown# | WA | 1ms | 5856kb | C++14 | 4.3kb | 2024-11-25 14:55:51 | 2024-11-25 14:55:52 |
Judging History
answer
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <random>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define xx first
#define yy second
// #define int long long
using namespace std;
const int N = 3e5 + 5, mod = 998244353, inf = 0x3f3f3f3f, inv2 = mod + 1 >> 1;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long long ll;
int ksm(int b, int e) {
int res = 1;
while (e) {
(e & 1) && (res = 1ll * res * b % mod);
b = 1ll * b * b % mod;
e >>= 1;
}
return res;
}
// int n, m;
// namespace G {
// int num, h[N], d[N], to[N << 2], nxt[N << 2];
// inline void adde(int x, int y) { ++ num; ++ d[x]; nxt[num] = h[x]; to[num] = y; h[x] = num; }
// bool calc() {
// queue<int> q;
// q.push(n + 1);
// while (!q.empty()) {
// const int x = q.front(); q.pop();
// for (int i = h[x]; i; i = nxt[i]) {
// const int y = to[i];
// -- d[y];
// if (!d[y]) q.push(y);
// }
// }
// for (int i = 1; i <= n; ++ i)
// if (d[i])
// return 0;
// return 1;
// }
// }
// namespace T {
// // void init(int nd, int l, int r) {
// // if (l == r) return;
// // const int mid = l + r >> 1;
// // adde(nd, nd << 1); adde(nd, nd << 1 | 1);
// // }
// // vector<int> getp(int nd, int l, int r, int L, int R) {
// // if (l <= L && r >= R) return {nd};
// // const int mid = L + R >> 1;
// // vector<int> res;
// // if (l <= mid) for (int a : getp(nd << 1, l, r, L, mid)) res.push_back(a);
// // if (r > mid) for (int a : getp(nd << 1 | 1, l, r, mid + 1, R)) res.push_back(a);
// // return res;
// // }
// void init() {
// for (int i = 1; i <= n + 1; ++ i)
// adde(i, i - 1);
// }
// }
int n, m;
ll tr[N << 2];
int tag[N << 2];
inline void addc(int nd) {
++ tag[nd];
tr[nd] <<= 1;
}
inline void down(int nd) {
if (tag[nd]) {
tag[nd << 1] += tag[nd];
tag[nd << 1 | 1] += tag[nd];
tr[nd << 1] <<= tag[nd];
tr[nd << 1 | 1] <<= tag[nd];
tag[nd] = 0;
}
}
void cg(int nd, int l, int r, int L, int R) {
if (l <= L && r >= R) return addc(nd);
const int mid = L + R >> 1; down(nd);
if (l <= mid) cg(nd << 1, l, r, L, mid);
if (r > mid) cg(nd << 1 | 1, l, r, mid + 1, R);
tr[nd] = tr[nd << 1] + tr[nd << 1 | 1];
}
inline pair<int, ll> get(ll val) {
int nd = 1, l = 1, r = n, mid;
ll sum = val;
while (l ^ r) {
down(nd);
mid = l + r >> 1;
if (tr[nd << 1] >= val) nd <<= 1, r = mid;
else val -= tr[nd << 1], nd = nd << 1 | 1, l = mid + 1;
}
return {l, sum - val};
}
inline int getd(int x) {
int nd = 1, l = 1, r = n, mid;
while (l ^ r) {
down(nd);
mid = l + r >> 1;
(x > mid) ? (nd = nd << 1 | 1, l = mid + 1) : (nd <<= 1, r = mid);
}
return nd;
}
inline void upd(int nd) { while (nd >>= 1) tr[nd] = tr[nd << 1] + tr[nd << 1 | 1]; }
void bt(int nd, int l, int r) {
tr[nd] = r - l + 1;
if (l == r) return;
const int mid = l + r >> 1;
bt(nd << 1, l, mid); bt(nd << 1 | 1, mid + 1, r);
}
void solve() {
cin >> n >> m;
string str;
cin >> str;
bt(1, 1, n);
while (m --) {
int op;
ll l, r, x;
cin >> op;
if (op == 1) {
cin >> l >> r;
auto [p1, s1] = get(l);
auto [p2, s2] = get(r);
if (p1 + 1 <= p2 - 1) cg(1, p1 + 1, p2 - 1, 1, n);
int n1 = getd(p1);
tr[n1] += s1 + tr[n1] - l + 1;
upd(n1);
int n2 = getd(p2);
tr[n2] += r - s2;
upd(n2);
} else {
cin >> x;
auto [p, s] = get(x);
cout << str[p - 1] << '\n';
}
}
}
main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T = 1;
// cin >> T;
while (T --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5856kb
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: 1ms
memory: 5632kb
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: 1ms
memory: 5628kb
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: 1ms
memory: 5664kb
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
Wrong Answer
time: 1ms
memory: 5632kb
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...
output:
f f f f f f v f f v v f f f f f f f v f f f f f v f v
result:
wrong answer 2nd lines differ - expected: 'e', found: 'f'