QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#785248#9791. Intrusive Donkeyucup-team4975#WA 0ms3824kbC++233.3kb2024-11-26 17:19:052024-11-26 17:19:07

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 17:19:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2024-11-26 17:19:05]
  • 提交

answer

#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
#define int long long
#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif

#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif

#ifdef LOCAL
#define debugv(x)                   \
    cerr << setw(4) << #x << ":: "; \
    for (auto i : x)                \
        cerr << i << " ";           \
    cerr << endl
#else
#define debugv(x)
#endif

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
    out << x.fir << " " << x.sec << endl;
    return out;
}

const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;

struct segtree {
	int l, r;
	ll tag, sum;
}t[N << 2];

void pushup(int p) {
	t[p].sum = t[p << 1].sum + t[p << 1 | 1].sum;
}

void pushdown(int p) {
	if (t[p].tag == 1) {
		return;
	}
	t[p << 1].sum = t[p << 1].sum * t[p].tag;
	t[p << 1 | 1].sum = t[p << 1 | 1].sum * t[p].tag;
	t[p << 1].tag *= t[p].tag;
	t[p << 1 | 1].tag *= t[p].tag;
	t[p].tag = 1;
}

void build (int p, int l, int r) {
	t[p].l = l, t[p].r = r, t[p].tag = 1;
	if (l == r) {
		t[p].sum = 1;
		return;
	}
	int mid = (l + r) >> 1;
	build (p << 1, l, mid);
	build(p << 1 | 1, mid + 1, r);
	pushup(p);
}

void modifylr(int p, int l, int r) {
	if (l <= t[p].l && t[p].r <= r) {
		t[p].tag *= 2;
		t[p].sum *= 2;
		return;
	}
	pushdown(p);
	if (l <= t[p << 1].r)
		modifylr(p << 1, l, r);
	if (r >= t[p << 1 | 1].l)
		modifylr(p << 1 | 1, l, r);
	pushup(p);
}

void modifyp(int p, int x, ll val) {
	if (t[p].l == t[p].r) {
		t[p].sum += val;
		return;
	}
	pushdown(p);
	if (x <= t[p << 1].r)
		modifyp(p << 1, x, val);
	if (x >= t[p << 1 | 1].l)
		modifyp(p << 1 | 1, x, val);
	pushup(p);
}

int getpl(int p, ll sum) {
	// cout << p << " " << sum << endl;
	if (t[p].l == t[p].r) {
		// cout << "!" << endl;
		return t[p].l;
	}
	pushdown(p);
	ll sum1 = t[p << 1].sum;
	if (sum1 >= sum)
		return getpl(p << 1, sum);
	else 
		return getpl(p << 1 | 1, sum - sum1);
	pushup(p);
}

ll getsum(int p, int l, int r) {
	if (l <= t[p].l && t[p].r <= r) {
		return t[p].sum;
	}
	pushdown(p);
	ll ans = 0;
	if (l <= t[p << 1].r)
		ans += getsum(p << 1, l, r);
	if (r >= t[p << 1 | 1].l)
		ans += getsum(p << 1 | 1, l, r);
	pushup(p);
	return ans;
}

void solve()
{
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	s = " " + s;
	build(1, 1, n);

	while (q--) {
		int inp;
		ll l, r, x;
		cin >> inp;
		if (inp == 1) {
			cin >> l >> r;
			int bl = getpl(1, l);
			int br = getpl(1, r);
			// cout << l << " " << r << " "<< bl << " " << br << endl;
			if (bl == br) {
				modifyp(1, bl, (r - l + 1));
			}
			else {
				ll len1 = getsum(1, 1, bl);
				ll len2 = getsum(1, 1, br - 1);

				modifyp(1, bl, len1 - l + 1);
				modifyp(1, br, r - len2);
				if (bl + 1 != br - 1) 
					modifylr(1, bl + 1, br - 1);
			}
		}
		else {
			cin >> x;
			// cout << getpl(1, x) << " ";
			cout << s[getpl(1, x)] << el;
		}
	}
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

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: 3612kb

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: 3824kb

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: 3548kb

input:

5 4
shrek
1 1 2
2 7
1 1 7
2 7

output:

k
h

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3616kb

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
e
f
f
f
f
v
f
e
f
f
f
e
e
e
f
e
e
f
e
e
e
f
e
f
e
v

result:

ok 27 lines

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3820kb

input:

60 51
ranhfkbjhkxckkcbhgsspsjcbjgpwcfvmqqlvlfualndmqqsihsfdyqviowu
2 53
2 37
2 33
2 60
1 1 32
2 44
1 87 92
1 7 77
1 56 86
2 17
1 128 184
1 26 159
2 323
2 55
1 24 316
1 435 652
2 316
2 444
1 819 868
2 27
2 912
2 313
1 555 576
1 510 942
1 1118 1269
2 365
2 84
1 595 650
2 1468
2 258
1 1557 1607
2 938
1...

output:

d
v
m
u
s
k
q
c
p
j
j
n
p
j
c
u
s
c
b
p
u
p
c
u
p
g

result:

wrong answer 24th lines differ - expected: 'n', found: 'u'