QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#365113 | #5516. Modern Machine | ksu_ | 25 | 382ms | 11716kb | C++23 | 5.3kb | 2024-03-24 19:53:32 | 2024-03-24 19:53:33 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,sse3")
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define endl '\n'
ll t[4 * 120007], mod[4 * 120007];
ll n, m;
void build(ll v, ll l, ll r, string &a){
if(l == r){
t[v] = (a[l] == '>' ? 1 : 0);
mod[v] = -1;
return;
}
ll mid = (l + r) >> 1;
build(2 * v, l, mid, a);
build(2 * v + 1, mid + 1, r, a);
t[v] = t[2 * v] + t[2 * v + 1];
mod[v] = -1;
}
void push(ll v, ll l, ll r){
if(l != r && mod[v] != -1){
ll mid = (l + r) >> 1;
t[2 * v] = (mid - l + 1) * mod[v];
t[2 * v + 1] = (r - mid) * mod[v];
mod[2 * v] = mod[v];
mod[2 * v + 1] = mod[v];
mod[v] = -1;
}
}
void update(ll v, ll l, ll r, ll ql, ll qr, ll val){
if(r < ql || qr < l)
return;
if(ql <= l && r <= qr){
t[v] = (r - l + 1) * val;
mod[v] = val;
return;
}
ll mid = (l + r) >> 1;
push(v, l, r);
update(2 * v, l, mid, ql, qr, val);
update(2 * v + 1, mid + 1, r, ql, qr, val);
t[v] = t[2 * v] + t[2 * v + 1];
}
ll getsum(ll v, ll l, ll r, ll ql, ll qr){
if(r < ql || qr < l)
return 0;
if(ql <= l && r <= qr)
return t[v];
ll mid = (l + r) >> 1;
push(v, l, r);
return getsum(2 * v, l, mid, ql, qr) + getsum(2 * v + 1, mid + 1, r, ql, qr);
}
ll getk1(ll v, ll l, ll r, ll pref, ll k){
if(pref < l)
return -1;
if(l == r)
return l;
push(v, l, r);
ll mid = (l + r) >> 1;
if(pref <= mid || t[2 * v] >= k)
return getk1(2 * v, l, mid, pref, k);
return getk1(2 * v + 1, mid + 1, r, pref, k - t[2 * v]);
}
ll getk0(ll v, ll l, ll r, ll pref, ll k){
if(pref < l)
return -1;
if(l == r)
return l;
push(v, l, r);
ll mid = (l + r) >> 1;
if(pref <= mid || (mid - l + 1) - t[2 * v] >= k)
return getk0(2 * v, l, mid, pref, k);
return getk0(2 * v + 1, mid + 1, r, pref, k - ((mid - l + 1) - t[2 * v]));
}
string simulation(string a, ll p){
for(int i = 1; i < a.size(); i++)
a[i] = (a[i] == '>' ? 'R' : 'B');
a[p] = 'R';
while(p >= 1 && p <= n){
if(a[p] == 'R'){
a[p] = 'B';
p++;
}
else{
a[p] = 'R';
p--;
}
}
for(int i = 1; i < a.size(); i++)
a[i] = (a[i] == 'R' ? '>' : '<');
return a;
}
int main(){
// n = 5;
// cout << simulation("#BBBBB", 4) << endl;
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
string a;
cin >> a;
for(auto &i: a)
i = (i == 'R' ? '>' : '<');
a = "#" + a;
vector<ll> d(m + 1);
for(int i = 1; i <= m; i++)
cin >> d[i];
ll q;
cin >> q;
auto a0 = a;
while(q--){
ll l, r;
cin >> l >> r;
a = a0;
build(1, 1, n, a);
for(int i = l; i <= r; i++){
ll left0 = 0, right = 0;
ll p = d[i];
update(1, 1, n, p, p, 1);
if(p != 1)
left0 = getsum(1, 1, n, 1, p - 1);
if(p != n)
right = (n - p) - getsum(1, 1, n, p + 1, n);
if(left0 >= right){
// sufix to '<'
ll need = right;
// find need-th obstacle (ie '>', 1) on the prefix
need = left0 - right + 1;
ll cur = p;
if(need != 0 && p != 1)
cur = getk1(1, 1, n, n, need);
update(1, 1, n, cur, n, 0);
}
else{
// prefix to '>'
ll need = left0 + 1;
// find need-th obstacle (ie '<', 0) on sufix
ll cur = p;
if(p != 1)
need = need + (p - 1) - getsum(1, 1, n, 1, p - 1);
if(p != n)
cur = getk0(1, 1, n, n, need);
//cout << need << ' ' << cur << endl;
update(1, 1, n, 1, cur, 1);
}
//a = simulation(a, p);
// cout << a << endl;
// for(int i = 1; i <= n; i++)
// cout << getsum(1, 1, n, i, i) << ' ';
// cout << endl;
}
ll ans = getsum(1, 1, n, 1, n);
cout << ans << endl;
}
return 0;
}
/*
10 10
RRRBBBBBBB
3 1 4 1 5 9 2 6 5 3
1
5 6
*/
详细
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 1ms
memory: 5592kb
input:
3 1 BBR 3 1 1 1
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5632kb
input:
3 10 BBB 3 3 3 1 3 3 3 3 3 1 1 2 5
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5580kb
input:
10 1 RBBBBRRBBR 9 1 1 1
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
10 10 RRRBBRRBRB 5 9 4 6 7 7 4 3 8 2 1 1 10
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
300 300 BRRRRBBRBRBRBBBRBRRRBRBBRBBRRBBRBBRBRBRBRBBRRBBRBBRBBBBRRRRBRBRBBBBRBBBRBBRBBRBRBRRBRBBRRRRBRBBRRRBRRBRBBBRRRRBRRRBBBBRRBBRBBBRRRBRBBRBRBBRRBRBRRRBRBRBBBBRRBRBRRRRRBRRRRRBRRRBRBRRRRRBBBRRBBRBBRRRRBBBBRBRBBBRRRRBBBBBBBBBBRBRRBRBBRRRRBRBBRRRBBRBRRRBBRBRRBBRBBBBRBRBRBBBRBBRBRBBRBBRBRBRBRRRBBBBR...
output:
29
result:
ok single line: '29'
Test #6:
score: 0
Accepted
time: 0ms
memory: 5844kb
input:
300 300 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
149
result:
ok single line: '149'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5640kb
input:
5 2 RBRBB 2 5 1 1 2
output:
4
result:
ok single line: '4'
Subtask #2:
score: 12
Accepted
Dependency #1:
100%
Accepted
Test #8:
score: 12
Accepted
time: 3ms
memory: 7832kb
input:
7000 7000 RRBRRRRRRBBRBRBRRRBRRRBRRRRBRBRBRBRBBBRBRRRBBBRBBBBBBRBBBRRBRBRBBRRRBBBBRRBBRBBRBBRRRBBRRBRBRRRRRBBRRBRBBBRBBRRRRBRBBBBRBBBBBBRRRBRBRBBRBRRBBBBBRRBBBBBBRBBBRRBBRRBBBBBBRBRBRBBRBBRBBBRRBRBBRBBBBBRBRRBRRBRRRBRBBBBBRRBRBRRBRRRRBBBBRRBBRRRRRBBBBBRRBBBBBBRRBBRBRRRRRRRBRRBRRBBBBBBBBRRRRBBRRRRRRR...
output:
5505
result:
ok single line: '5505'
Test #9:
score: 0
Accepted
time: 2ms
memory: 5864kb
input:
7000 7000 RRBRRRBBRRBBRBBBBRBRBRRBBBBBBBBBBRRRBRRBBRRRRBBRRBRRRRRBBRBBBBBRRBBBBRBBBBRBRBBBBBRBBRRRBBBBRRBRRBRRBRBBBRRRRBBRRBRRBRBBRBBBRBBBRRBRBBBRRBBBBBRBBRBRBRBBBBRRBBBRRRRBRRBBRBRBBBBBBRRRRRBBRRBBRRBBBRBBBRRRRRBRBBRBRBBRRBBRBRRRBBRRBBBRRBRRRRRRRBBRBRRBRBRBRBRBRBBRBRRBRBBBBBBBRRBRRRBBBBRRBBRRRBBRBR...
output:
5936
result:
ok single line: '5936'
Test #10:
score: 0
Accepted
time: 3ms
memory: 5852kb
input:
7000 7000 RBBRBRBRRRBBRBRRBRBBRBRRRBRBBBRBBRBRBRBRRBBBBRBRRRBBRRRRBBRRRRBBRBRBRRRRBBRRBBRBRBBBRBBBBBRBBRBBRRBBRRRRRBBRBRBRRBBRRRBRBBBRBRRBRRRBRRRBRBBBBRBBBBBBRBRRRBRRRBRBBBRBRRBBRRBRRBBBBBRBBRRRRBBRRBBBBRRBRBRRRRBBRRRRRBRBRRBBRRRRRBRRBRBBBBRRBBBBRBRRRBBRBRRRRRBRRBRRRBRRBRRRRRBBBRBBBRBRRRBRBBBBRRRRRR...
output:
6260
result:
ok single line: '6260'
Test #11:
score: 0
Accepted
time: 2ms
memory: 5740kb
input:
7000 7000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
output:
3499
result:
ok single line: '3499'
Test #12:
score: 0
Accepted
time: 1ms
memory: 7764kb
input:
7000 7000 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
3906
result:
ok single line: '3906'
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #13:
score: 10
Accepted
time: 176ms
memory: 10220kb
input:
120000 120000 BBBBRBBRBRRBRRRBBBRRRRRBRRRRRRRRRRRBBBBRBRBBBBBBRBRBBBRBBRBRRBBRBRRRBRBBBBBRBRRBBRRRRRBBRBBBBRBBRRBRRRRBRBBBRRRBBBRRBRRBBBRRRBRRRBBRBBRRRBBBRBBRBBBBBRBRRRRBBRBRBRBBRRRRRRRBBRRBBBBRRRBBRRRRRBBBBRBBBBRBRRBBBRBRBBBRBRBRRBBRBRBBBRRBBRBBBBRBBRRBRBRBRBRRBBRBBBBBBBRRRRBRBRBRBRRRRBRRBBBRBRRBRB...
output:
110620 106126 106019 110676 111965
result:
ok 5 lines
Test #14:
score: 0
Accepted
time: 217ms
memory: 11512kb
input:
120000 120000 BRRBBBRRRRRRRBRRRRRRRBBRBBRRBBRRRRRBRBRRBRRRRRBRRBBBBRRBRRRBBBBRRBRBRBBBRBBRRBRRRBRRBRBBBBRRRBRBRBRBBBBRBRRRBRBBRBBBRRBBBRBBBBRRBBRRBBRBRRRBBBRBBBRRRRBBBBBRRRRBBBBBBBRRRRRRRBBBRRRBBRRRRBBBRBBBRRBBBRRRRRRRRRRRRRBRRBRRBRBRRBBBBBBRRRRBRRBRBBBBRRBRRRRRBRRBRRRBBRRRBBRRRRRBRBRRRRBBBBBBBRBRRR...
output:
96348 101002 105432 99656 104213
result:
ok 5 lines
Test #15:
score: 0
Accepted
time: 318ms
memory: 11208kb
input:
120000 120000 BRBRRBBBRBRBRRRRBRRRRBBRBRBBBBBBBRBBRRBRRRRRBRRRRBBBRRRBBRRBBRRBBBRBRRRBBRRRBBRRBRRRRRBRRBRBRBRRRRBRRRRBRBRBRRRBBBBRBBRRBRBRRBBRRBBBBRBRRRBRRRRBBBRBBRBBRRBBBBBBBBRBBBBRRBBBRRBRRRRRRBBRBRBRRRBBRRRRBBBBRBBBRBRBRBRBBRRRBBBBBBRRRRRRBRBBRRRRBRBBBRBBRBRRRRBBBRRRBBRBRRBBBRBRRBRRRRRRRBBRRRBRRB...
output:
21951 100124 2164 9705 84183
result:
ok 5 lines
Test #16:
score: 0
Accepted
time: 382ms
memory: 10972kb
input:
120000 120000 BBRBRRRRRBRRBBBBBRBRRBRRBBRBRRBBBBBBBBRRRBBBBRRBRRRBRBBBRRRBRBBRRBBBBBBBRBBRBBBBRBBBBBRRRRRRBBBRRRBRRRRRBRRBRBBRBBBRBBRRBRRRRRRRRRBRRRRBRRRBBRRBBBBRBBRBBBBRRBRRBBBRRRRRBRBRBRRRRRRRBRRBBBBBRRBBRRRBBRBBBRBBBRBRBRRRBBBBRRBRBBBRRRBBRBBBBBRBRRBBBRRRBRBRRRRRRBBRRRBRBBBBRRRBBBRBBBRBBRRRRRBBBR...
output:
1538 12691 15538 71544 59943
result:
ok 5 lines
Test #17:
score: 0
Accepted
time: 211ms
memory: 11052kb
input:
120000 120000 RRBRBBBRRBRBBBBRRBRBBRRRBRRBRBBBRRBBBBBRBRRBRBBRRRRBRBRRBRBRBRBRBRRRBBRRRRRBBBRRBRBBRRBRBRRBRRBBBBBBRBRRBBBBBBRBBBRBBRRRRBBRBBRRRBRBRRBBBRRRBBRBRBBBRBRBBRRRBBBBRRBBRRBRBBBBRRBBRRRRRRRBBRBRBBBRBRBRBBRBBRRRBBBRBRBRBBBBRBBRBBBRRBRRRRRBRBRBBRRRRRRBBBRBBRRRRRRRRRRBBBBRRBBRRBBRBRRBRRRBBRBRRR...
output:
40188 86078 5895 13418 41515
result:
ok 5 lines
Test #18:
score: 0
Accepted
time: 184ms
memory: 11716kb
input:
120000 120000 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
92747 92740 60010 68177 92504
result:
ok 5 lines
Test #19:
score: 0
Accepted
time: 201ms
memory: 10792kb
input:
120000 120000 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
24163 77301 16491 24538 26597
result:
ok 5 lines
Test #20:
score: 0
Accepted
time: 201ms
memory: 10732kb
input:
120000 120000 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
output:
21975 61282 31752 20423 27041
result:
ok 5 lines
Subtask #4:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
input:
10 120000 RRRRRRRRRR 9 1 9 6 1 9 6 10 3 2 6 4 2 5 7 10 8 9 2 6 7 10 2 9 7 5 9 9 2 7 4 1 8 3 3 6 9 4 7 9 6 8 8 2 5 6 8 3 9 2 5 2 5 9 8 4 8 3 2 2 5 1 9 1 7 9 9 4 9 5 2 10 7 4 3 8 1 10 7 6 6 2 3 8 7 8 5 9 2 2 1 10 2 2 5 4 2 5 9 1 8 4 5 1 2 8 3 10 10 6 7 2 1 5 10 1 9 10 1 7 3 10 8 10 6 8 3 1 10 9 10 5 5...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #26:
score: 0
Time Limit Exceeded
input:
120000 120000 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #30:
score: 0
Time Limit Exceeded
input:
120000 120000 RRBBRBRBBBRBRRBRBRRRBRBRRBRRRBBRBBBBBBRBBRBRBRBRRBRBRBRRRBRBBBBRRBBRRBBRRRBRRBRBBRRRBBBRRBBBBRBBBRBBBRBBBRBBRBBBBRBBBBRRBRRRRRRRBRRRBRBBBRBBBBRBBRBRBRRBBRRBRBBBBRBBBRBBRRBBBBRBBBBRBRRBRBBRBBBBRRBBBBBBRBBRBBBBBBRBBRRRRRBBBRBBBRBRRBBRBRBRBBRRBRRBBBRBRBRRRBBRRBBRRRRBRRBBRRBBBBBBBRBBBRBBBR...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
0%