QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#311830 | #186. Street Lamps | oyzr | 20 | 1072ms | 142656kb | C++14 | 3.4kb | 2024-01-22 20:44:44 | 2024-01-22 20:44:44 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 3e5 + 5, maxk = 3e5 + 5;
struct Node{
int a, b, c;
int id;
int val;
bool operator < (const Node T) const{
if (a == T.a)
if (b == T.b)
return c < T.c;
else
return b < T.b;
else
return a < T.a;
}
}t[8 * maxn], tmp[8 * maxn];
int pos = 0;
int k;
struct Tree_Array{
private:
int tree[maxk];
int lowbit(int x){return x & (-x);}
public:
void add(int id, int val){
while (id <= k){
tree[id] += val;
id += lowbit(id);
}
}
int sum(int id){
int res = 0;
while (id > 0){
res += tree[id];
id -= lowbit(id);
}
return res;
}
}Tree;
int ans[maxn];
void cdq(int L, int R){
if (L == R)
return;
int mid = (L + R) >> 1;
cdq(L, mid);
cdq(mid + 1, R);
int i = L, j = mid + 1, k = L;
while (i <= mid && j <= R){
if (t[i].b <= t[j].b){
Tree.add(t[i].c, t[i].val);
tmp[k++] = t[i++];
}else{
ans[t[j].id] += Tree.sum(t[j].c);
tmp[k++] = t[j++];
}
}
int ii = i - 1;
while (i <= mid)
tmp[k++] = t[i++];
while (j <= R){
ans[t[j].id] += Tree.sum(t[j].c);
tmp[k++] = t[j++];
}
for (int i = L; i <= ii; i++)
Tree.add(t[i].c, -t[i].val);
for (int i = L; i <= R; i++)
t[i] = tmp[i];
}
int n, q;
set <int> S; //存不连通的路
set <int>::iterator it;
int less_num(int x){
if (S.empty())
return 0;
it = S.lower_bound(x);
if (it == S.begin())
return 0;
return *(--it);
}
int greater_num(int x){
if (S.empty())
return n + 1;
it = S.lower_bound(x);
if (it == S.end())
return n + 1;
return *(it);
}
void add_rectangle(int T, int x1, int y1, int x2, int y2, int val){
t[++pos] = {T, x1, y1, 0, val};
t[++pos] = {T, x2 + 1, y2 + 1, 0, val};
t[++pos] = {T, x1, y2 + 1, 0, -val};
t[++pos] = {T, x2 + 1, y1, 0, -val};
}
void add(int T, int x){
S.erase(x);
int l = less_num(x) + 1;
int r = greater_num(x + 1);
add_rectangle(T, l, x + 1, x, r, q - T);
}
void del(int T, int x){
S.insert(x);
int l = less_num(x) + 1;
int r = greater_num(x + 1);
add_rectangle(T, l, x + 1, x, r, -(q - T));
}
char s[maxn];
int a[maxn];
bool is_query[maxn];
signed main(){
cin >> n >> q;
k = n + 1;
cin >> s + 1;
for (int i = 1; i <= n; i++)
a[i] = s[i] - '0';
for (int i = 1; i <= n; i++)
S.insert(i);
for (int i = 1; i <= n; i++){
if (a[i]){
add(0, i);
}
}
string opt;
int x, y;
for (int T = 1; T <= q; T++){
cin >> opt;
if (opt == "query"){
is_query[T] = true;
cin >> x >> y;
t[++pos] = {T, x, y, T, 0};
}else{
cin >> x;
if (a[x] == 0){
a[x] = 1;
add(T, x);
}else{
a[x] = 1;
del(T, x);
}
}
}
sort(t + 1, t + pos + 1);
cdq(1, pos);
for (int T = 1; T <= q; T++)
if (is_query[T])
cout << (ans[T] ? ans[T] - (q - T): 0) << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 20
Accepted
time: 1ms
memory: 3568kb
input:
5 7 11011 query 1 2 query 1 2 query 1 6 query 3 4 toggle 3 query 3 4 query 1 6
output:
1 2 0 0 1 2
result:
ok 6 lines
Test #2:
score: -20
Wrong Answer
time: 1ms
memory: 3612kb
input:
5 50 01001 query 1 6 toggle 3 toggle 3 toggle 2 toggle 3 toggle 2 toggle 4 query 2 6 query 2 3 query 1 3 query 3 5 toggle 3 query 2 6 query 1 5 query 2 3 query 3 6 toggle 5 toggle 1 toggle 2 toggle 4 query 1 6 query 4 5 toggle 3 query 5 6 toggle 2 query 4 6 toggle 5 toggle 5 toggle 2 query 4 5 query...
output:
0 0 -81 0 0 0 0 -75 -72 0 -15 -9 -14 -7 -57 -56 -108 -164 0 0 0 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 375ms
memory: 64856kb
input:
100 300000 1100100000000101010010100111010001100010001100111101000010111110001101101110100100100110101010110010 query 13 14 query 42 43 toggle 64 query 78 79 toggle 85 query 35 36 toggle 35 query 4 5 toggle 5 query 4 5 query 42 43 query 35 36 query 13 14 query 14 15 toggle 15 toggle 31 query 20 21 q...
output:
0 0 0 6 0 0 0 -299981 0 14 0 18 0 0 21 0 26 0 0 36 38 15 41 44 0 47 20 50 52 0 55 52 56 0 -299900 31 70 73 7 4 0 0 51 83 84 90 -599844 0 95 97 0 70 0 103 26 8 -299840 -299860 -299770 122 -299857 -299766 -299765 0 0 -299841 0 135 139 112 -299824 142 -599745 146 0 151 0 153 0 0 73 0 164 0 -299731 0 -2...
result:
wrong answer 8th lines differ - expected: '7', found: '-299981'
Subtask #3:
score: 20
Accepted
Test #17:
score: 20
Accepted
time: 2ms
memory: 3912kb
input:
1000 1003 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0 0 0
result:
ok 3 lines
Test #18:
score: 0
Accepted
time: 3ms
memory: 4028kb
input:
1000 1003 00100001101000000001000001001000100010000010010010001001001010001010101100010001000010101100000001001111000001110000010110100000100110001000000101001110000001110001000100000011001110000011010100101000000010100110100010000000110000111100100000011000100010010100000000100000000010001001110101...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 304 lines
Test #19:
score: 0
Accepted
time: 3ms
memory: 4036kb
input:
1000 1003 11001001111000111100001101101111110010111101110100101000111001111011110111110111111001110011111110111110101110011101111111111111010111010100011010011100101011111001111010111110111010111011101100100111010000110101110001000011100010111110011001010110101111011101100110001100111000000011000111...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 70 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 595 lines
Test #20:
score: 0
Accepted
time: 3ms
memory: 4064kb
input:
1000 1003 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 1003 lines
Test #21:
score: 0
Accepted
time: 1016ms
memory: 119228kb
input:
300000 300000 0000000000000000000000000000000000000000000000000100000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 2993 lines
Test #22:
score: 0
Accepted
time: 1051ms
memory: 126020kb
input:
300000 300000 0011010101100001010010010000110110001001001010100100100000011000001000000011000001000000000000011000000000001001000100100110001001100000000100000010111000000100000000010001000010010000111100010000010100001010100010000100000000111011000000110100000000010010000011010000100100011100000000...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 90028 lines
Test #23:
score: 0
Accepted
time: 1072ms
memory: 133272kb
input:
300000 300000 0100110101111011111000101011001011100101011100111110111101110111001101110101111011011110110110110100011011110101100111101001010110011110111010100111100101011110011011011011110100100101011111101111101010111011111111001101100011110011011001010011111111101110101101010011110111011110101011...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 180075 lines
Test #24:
score: 0
Accepted
time: 968ms
memory: 142460kb
input:
300000 300000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 300000 lines
Test #25:
score: 0
Accepted
time: 211ms
memory: 24904kb
input:
100 242447 1000110110111111100100010100111000111001101111100000100110110000011111010011100101101110101001101000 query 1 2 query 1 3 query 1 4 query 1 5 query 1 6 query 1 7 query 1 8 query 1 9 query 1 10 query 1 11 query 1 12 query 1 13 query 1 14 query 1 15 query 1 16 query 1 17 query 1 18 query 1 1...
output:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 242400 lines
Test #26:
score: 0
Accepted
time: 180ms
memory: 26784kb
input:
90 266239 000010000000110000000100001010000111010000100100010000001100000110011000100000001101111000 query 1 2 query 1 3 query 1 4 query 1 5 query 1 6 query 1 7 query 1 8 query 1 9 query 1 10 query 1 11 query 1 12 query 1 13 query 1 14 query 1 15 query 1 16 query 1 17 query 1 18 query 1 19 query 1 2...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 266175 lines
Test #27:
score: 0
Accepted
time: 191ms
memory: 26792kb
input:
130 263995 1000111111101111101111011111011111111010111111010110011111111111100111010111111101111011111111111111111010101101100011101101111010 query 1 2 query 1 3 query 1 4 query 1 5 query 1 6 query 1 7 query 1 8 query 1 9 query 1 10 query 1 11 query 1 12 query 1 13 query 1 14 query 1 15 query 1 16 q...
output:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 263965 lines
Test #28:
score: 0
Accepted
time: 447ms
memory: 48828kb
input:
300000 300000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 300000 lines
Test #29:
score: 0
Accepted
time: 946ms
memory: 142656kb
input:
300000 300000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 300000 lines
Subtask #4:
score: 0
Wrong Answer
Test #30:
score: 20
Accepted
time: 0ms
memory: 3868kb
input:
1000 1003 10111011001010101101100010101100100010100110001000000001001100111110101100110100010001111101101100110111110100011000111101100100000110110010101011101001101110111100010100100000110001010001111101001010100101011111010000001110111110001011010111101100000001001110101110011111000101101100011010...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 991 lines
Test #31:
score: -20
Wrong Answer
time: 0ms
memory: 4116kb
input:
1000 1003 01000000111001001110011100111111110011010010110000100010101101101011100011010100100100110101110101010111011100110100110000001010110001011011011010001001101000111011001000000001001100101100010101011101000000101110111011011101100001011110111011001010011101000110100011000101011101000110001011...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 550th lines differ - expected: '92', found: '-59'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%