-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNERD2.cpp
More file actions
61 lines (54 loc) · 869 Bytes
/
Copy pathNERD2.cpp
File metadata and controls
61 lines (54 loc) · 869 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int N;
scanf("%d",&N);
map<int, int> nerd;
int ans=0;
for(int i=0; i < N; i++)
{
int problem, ramen;
scanf("%d%d", &problem, &ramen);
map<int,int>::iterator it = nerd.lower_bound(problem);
if(it != nerd.end() && it->second > ramen)
{
ans += nerd.size();
continue;
}
if(it != nerd.begin())
{
--it;
while(true)
{
if(it->second > ramen)
break;
if(it == nerd.begin())
{
nerd.erase(it);
break;
}
else
{
map<int, int>::iterator jt = it;
--jt;
nerd.erase(it);
it = jt;
}
}
}
nerd[problem] = ramen;
ans += nerd.size();
}
cout << ans << '\n';
}
return 0;
}