-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKattis Supercomputer.cpp
More file actions
43 lines (38 loc) · 904 Bytes
/
Kattis Supercomputer.cpp
File metadata and controls
43 lines (38 loc) · 904 Bytes
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
//
// Created by Alon on 30/06/2020.
//
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MAX_FOR_H 1000001
int BIT[MAX_FOR_H] = {0}, n;
void update(int x, int val) { for (; x <= n; x += x & -x) BIT[x] += val; }
int query(int x) {
int sum = 0;
for (; x > 0; x -= x & -x) sum += BIT[x];
return sum;
}
int main() {
int K;
cin >> n >> K;
while (K--) {
char c;
cin >> c;
if (c == 'F') {
int num;
cin >> num;
int c = (query(num) - query(num-1) == 1) ? -1 : 1;
update(num, c);
} else { // case C
int start, end;
cin >> start >> end;
cout << query(end) - query(start-1) << endl;
}
}
return 0;
}