-
Notifications
You must be signed in to change notification settings - Fork 0
/
L01-2.cpp
51 lines (37 loc) · 1004 Bytes
/
L01-2.cpp
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
#include "simplification.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
#define fi first
#define se second
#define PUB push_back
int grup = 1, byk;
vector<int>angka;
void init(int N, std::vector<int> C) {
byk = N;
angka.PUB(C[0]);
for(int i=1;i<N;i++){
angka.PUB(C[i]);
if(C[i] != C[i-1]) grup++;
}
// cerr << "grup: " << grup << endl;
}
int update(int x, int c) {
x--;
if(angka[x] != c){
if(x==0){
if(angka[x] == angka[x+1]) grup++;
if(c == angka[x+1]) grup--;
}else if(x==byk-1){
if(angka[x] == angka[x-1]) grup++;
if(c == angka[x-1]) grup--;
}else{
if(angka[x] == angka[x-1] && angka[x] == angka[x+1]) grup += 2;
else if(angka[x] == angka[x-1] || angka[x] == angka[x+1]) grup++;
if(c == angka[x-1] && c == angka[x+1]) grup -= 2;
else if(c == angka[x-1] || c == angka[x+1]) grup--;
}
angka[x] = c;
}
return byk-grup;
}