QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136226#186. Street LampsMohammed_Atalah#0 107ms16392kbC++173.4kb2023-08-07 17:10:342024-07-04 01:23:39

Judging History

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

  • [2024-07-04 01:23:39]
  • 评测
  • 测评结果:0
  • 用时:107ms
  • 内存:16392kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-07 17:10:34]
  • 提交

answer

/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}

// cout << fixed;
// cout << setprecision(4);


// ---------(^_^)--------- //


struct segtree {

	int size = 1;

	vector<int> mx;
	void init(int n) {
		while (size < n)size *= 2;
		mx.assign(2 * size, -1);
	}

	void build(vector<int>&v, int x, int  lx, int rx) {
		if (rx - lx == 1) {
			if (lx < v.size()) {
				mx[x] = v[lx];
			}
			return;
		}

		int m = (lx + rx) / 2;
		build(v, 2 * x + 1, lx, m);
		build(v, 2 * x + 2, m, rx);
		mx[x] = max(mx[2 * x + 1] , mx[2 * x + 2]);
	}

	void build(vector<int> &v) {
		build(v, 0, 0, size);
	}


	void set(int i, int v, int x, int lx, int rx) {
		if (rx - lx == 1) {
			mx[x] = v;
			return;
		}

		int m = (lx + rx) / 2;

		if (i < m) {
			set(i, v, x * 2 + 1, lx, m);
		} else {
			set(i, v, x * 2 + 2, m, rx);
		}

		mx[x] = max(mx[2 * x + 1] , mx[2 * x + 2]);
	}

	void set(int i, int v) {
		set(i, v, 0, 0, size);
	}


	int maxel (int l, int r, int x, int lx, int rx) {
		if (rx <= l || r <= lx )return -1;
		if (l <= lx && rx <= r) return mx[x];
		int m = (rx + lx) / 2;
		int n1 = maxel(l, r, x * 2 + 1, lx, m );
		int n2 = maxel(l, r, x * 2 + 2, m, rx );
		return max(n1 , n2);

	}

	int maxel(int l, int r) {
		return maxel(l, r, 0, 0, size);
	}



};



void main_solve() {
	int n, q; cin >> n >> q;
	string s; cin >> s;
	vector<int> v(n);
	for (int i = 0; i < n ; i ++) {
		if (s[i] == '1') {
			v[i] = 0;
		} else {
			v[i] = 1e7;
		}
	}

	segtree st;
	st.init(n);
	st.build(v);
	vector<int> result(n);
	int curr_time = 0;
	while (q--) {
		curr_time++;
		string type; cin >> type;

		if (type == "toggle") {
			int x; cin >> x;
			if (s[x - 1] == '0') {
				s[x - 1] = '1';
				st.set(x - 1, curr_time);
			} else {
				s[x - 1] = '0';
				st.set(x - 1, 1e7);
			}
		} else {
			int a, b; cin >> a >> b;
			int e = st.maxel(a - 1, b);
			if (e == 1e7 || e == -1) {
				cout << 0 << endl;
			} else {
				cout << curr_time - e << endl;
			}
		}



	}





}


int32_t main() {

	fast;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	// Just another problem (-_-)

	int t;
	t = 1;
	// cin >> t;

	while (t--) {
		main_solve();
	}


}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 3752kb

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: 0ms
memory: 3608kb

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
1
3
0
4
0
0
0
0
0
0
0
0
0
0
0
1
2
0
0
0
0
0
0
0

result:

wrong answer 3rd lines differ - expected: '7', found: '3'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 48ms
memory: 3548kb

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
0
0
0
0
0
0
0
0
18
0
0
21
0
1
0
0
36
8
15
0
44
0
0
20
20
52
0
0
52
56
0
0
0
70
73
0
0
0
0
6
46
84
0
0
0
0
97
0
0
0
0
26
0
0
0
0
59
0
0
0
0
0
0
0
0
0
112
0
6
0
61
0
121
0
35
0
0
73
0
45
0
0
0
0
0
63
0
0
26
0
0
0
0
0
0
0
0
200
0
0
0
208
0
0
0
0
0
0
119
0
0
0
0
0
0
7
0
0
0
0
0
16
0
21
84
70
0
0
0...

result:

wrong answer 4th lines differ - expected: '6', found: '0'

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 20
Accepted
time: 1ms
memory: 3568kb

input:

1000 1003
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0

result:

ok 3 lines

Test #18:

score: 0
Accepted
time: 1ms
memory: 3660kb

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: 1ms
memory: 3852kb

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: 1ms
memory: 3664kb

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: 66ms
memory: 16380kb

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: 85ms
memory: 16392kb

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: -20
Wrong Answer
time: 107ms
memory: 16332kb

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:

wrong answer 60896th lines differ - expected: '101350', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #30:

score: 0
Wrong Answer
time: 1ms
memory: 3792kb

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:

wrong answer 262nd lines differ - expected: '274', found: '0'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%