QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#776702 | #9791. Intrusive Donkey | ucup-team3670# | WA | 0ms | 3828kb | C++20 | 2.7kb | 2024-11-23 20:22:21 | 2024-11-23 20:22:21 |
Judging History
answer
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define sz(a) (int)((a).size())
using namespace std;
typedef long long li;
vector<li> ps, t;
void push(int v){
if (ps[v] == 1) return;
if (v * 2 + 1 < sz(t)){
ps[v * 2] *= ps[v];
ps[v * 2 + 1] *= ps[v];
}
t[v] *= ps[v];
ps[v] = 1;
}
void build(int v, int l, int r){
if (l == r - 1){
t[v] = 1;
return;
}
int m = (l + r) / 2;
build(v * 2, l, m);
build(v * 2 + 1, m, r);
t[v] = t[v * 2] + t[v * 2 + 1];
}
int getl(int v, int l, int r, li &lft){
push(v);
if (l == r - 1){
if (lft - t[v] >= 0){
lft -= t[v];
return 1;
}
return 0;
}
int m = (l + r) / 2;
int res;
if (lft - t[v * 2] * ps[v * 2] <= 0){
push(v * 2 + 1);
res = getl(v * 2, l, m, lft);
}
else{
push(v * 2);
lft -= t[v * 2];
res = getl(v * 2 + 1, m, r, lft) + (m - l);
}
t[v] = t[v * 2] + t[v * 2 + 1];
return res;
}
li get(int v, int l, int r, int pos){
push(v);
if (l == r - 1)
return t[v];
int m = (l + r) / 2;
li res;
if (pos < m){
res = get(v * 2, l, m, pos);
push(v * 2 + 1);
}
else{
push(v * 2);
res = get(v * 2 + 1, m, r, pos);
}
t[v] = t[v * 2] + t[v * 2 + 1];
return res;
}
void mul(int v, int l, int r, int L, int R){
push(v);
if (L >= R)
return;
if (l == L && r == R){
ps[v] *= 2;
push(v);
return;
}
int m = (l + r) / 2;
mul(v * 2, l, m, L, min(m, R));
mul(v * 2 + 1, m, r, max(m, L), R);
t[v] = t[v * 2] + t[v * 2 + 1];
}
void add(int v, int l, int r, int pos, li val){
push(v);
if (l == r - 1){
t[v] += val;
return;
}
int m = (l + r) / 2;
if (pos < m){
add(v * 2, l, m, pos, val);
push(v * 2 + 1);
}
else{
push(v * 2);
add(v * 2 + 1, m, r, pos, val);
}
t[v] = t[v * 2] + t[v * 2 + 1];
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
string s;
cin >> s;
t.assign(4 * n, 0);
ps.assign(4 * n, 1);
build(1, 0, n);
forn(i, m){
int t;
cin >> t;
if (t == 1){
li l, r;
cin >> l >> r;
--l;
li len = r - l;
int L = getl(1, 0, n, l);
int R = getl(1, 0, n, r);
//cerr << L << " " << R << " " << l << " " << r << endl;
if (L == R){
add(1, 0, n, L, len);
}
else{
mul(1, 0, n, L, R);
if (l != 0)
add(1, 0, n, L - 1, get(1, 0, n, L - 1) - l);
if (r != 0)
add(1, 0, n, R, r);
}
}
else{
li pos;
cin >> pos;
--pos;
//cerr << ::t[1] * ps[1] << endl;
int x = getl(1, 0, n, pos);
//cerr << x << " ";
cout << s[x] << '\n';
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 3608kb
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: 3600kb
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: 3596kb
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: 0ms
memory: 3828kb
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 f f f f f f f f f f f f f f f f f f
result:
wrong answer 2nd lines differ - expected: 'e', found: 'f'