-
Notifications
You must be signed in to change notification settings - Fork 1
/
牛客网-二分-差分.cpp
62 lines (62 loc) · 1.33 KB
/
牛客网-二分-差分.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
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
#include<map>
using namespace std;
const int maxn = 9000000;
map<int, int> m;
int b[maxn]; //差分数组
map<int, int> a;
int main()
{
int n;
cin >> n;
int num;
char c;
for(int i = 1; i <= n; i++)
{
cin >> num >> c;
if(c == '.')
{
//猜到答案了
m[num] += 1;
m[num+1] -= 1;
//b[num] += 1;
//b[num+1] -= 1;
}
else
{
if(c == '+')
{
//数字比答案大
m[0] += 1;
m[num] -= 1;
//b[0] += 1;
//b[num] -= 1;
}
else if(c == '-')
{
//数字比答案小
m[num+1] += 1;
//b[num] += 1;
}
}
}
//还原数组
a[0] = m[0];
int max_time = a[0];
map<int, int>::iterator it;
int last_index = 0;
for(it = m.begin(); it != m.end(); it++)
{
if(it->first == 0){
continue;
}
a[it->first] = a[last_index] + it->second;
if(a[it->first] > max_time)
{
max_time = a[it->first];
}
last_index = it->first;
}
cout << max_time;
return 0;
}