#include <bits/stdc++.h>
using namespace std;
vector<int> in[200001];
multiset<int> s;
const int sz=262144;
int seg[sz*2];
int lazy[sz*2];
vector<int> put[200001];
vector<int> er[200001];
void propagate(int node) {
if (lazy[node]!=0) {
seg[node]+=lazy[node];
if (node<sz) {
lazy[node*2]+=lazy[node];
lazy[node*2+1]+=lazy[node];
}
lazy[node]=0;
}
}
int sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
propagate(node);
if (r<nodel||l>noder) {
return 1e9;
}
if (l<=nodel&&noder<=r) {
return seg[node];
}
int mid=(nodel+noder)/2;
return min(sum(l,r,node*2,nodel,mid),sum(l,r,node*2+1,mid+1,noder));
}
void update(int l,int r,int val,int node=1,int nodel=0,int noder=sz-1) {
propagate(node);
if (r<nodel||l>noder) {
return;
}
if (l<=nodel&&noder<=r) {
lazy[node]+=val;
propagate(node);
return;
}
int mid=(nodel+noder)/2;
update(l,r,val,node*2,nodel,mid);
update(l,r,val,node*2+1,mid+1,noder);
seg[node]=min(seg[node*2],seg[node*2+1]);
}
int main(void) {
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<m;i++) {
int a,b;
scanf("%d %d",&a,&b);
if (a>b) {
swap(a,b);
}
in[b].push_back(a);
put[a].push_back(a);
er[b].push_back(a);
}
for(int i=1;i<=n;i++) {
sort(in[i].begin(),in[i].end());
}
for(int j=0;j<put[1].size();j++) {
s.insert(put[1][j]);
}
for(int j=0;j<er[1].size();j++) {
s.erase(s.find(er[1][j]));
}
for(int i=2;i<=n;i++) {
int mini;
if (in[i].empty()) {
mini=i-1;
}
else {
mini=in[i][0]-1;
}
update(1,mini,1);
for(int j=0;j<put[i].size();j++) {
s.insert(put[i][j]);
}
for(int j=0;j<er[i].size();j++) {
s.erase(s.find(er[i][j]));
}
int en;
if (!s.empty()) {
en=(*s.begin())-1;
}
else {
en=i-1;
}
int val=sum(1,min(en,i-1));
update(i,i,val);
}
printf("%d",sum(n,n));
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int j=0;j<put[1].size();j++) {
| ~^~~~~~~~~~~~~~
Main.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int j=0;j<er[1].size();j++) {
| ~^~~~~~~~~~~~~
Main.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int j=0;j<put[i].size();j++) {
| ~^~~~~~~~~~~~~~
Main.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int j=0;j<er[i].size();j++) {
| ~^~~~~~~~~~~~~
Main.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d %d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
9 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14400 KB |
Output is correct |
4 |
Correct |
9 ms |
14412 KB |
Output is correct |
5 |
Correct |
9 ms |
14412 KB |
Output is correct |
6 |
Correct |
9 ms |
14476 KB |
Output is correct |
7 |
Correct |
9 ms |
14412 KB |
Output is correct |
8 |
Correct |
9 ms |
14380 KB |
Output is correct |
9 |
Correct |
9 ms |
14412 KB |
Output is correct |
10 |
Correct |
11 ms |
14540 KB |
Output is correct |
11 |
Correct |
10 ms |
14504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
9 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14400 KB |
Output is correct |
4 |
Correct |
9 ms |
14412 KB |
Output is correct |
5 |
Correct |
9 ms |
14412 KB |
Output is correct |
6 |
Correct |
9 ms |
14476 KB |
Output is correct |
7 |
Correct |
9 ms |
14412 KB |
Output is correct |
8 |
Correct |
9 ms |
14380 KB |
Output is correct |
9 |
Correct |
9 ms |
14412 KB |
Output is correct |
10 |
Correct |
11 ms |
14540 KB |
Output is correct |
11 |
Correct |
10 ms |
14504 KB |
Output is correct |
12 |
Correct |
10 ms |
14412 KB |
Output is correct |
13 |
Correct |
9 ms |
14412 KB |
Output is correct |
14 |
Correct |
9 ms |
14400 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14412 KB |
Output is correct |
17 |
Correct |
9 ms |
14476 KB |
Output is correct |
18 |
Correct |
9 ms |
14412 KB |
Output is correct |
19 |
Correct |
9 ms |
14380 KB |
Output is correct |
20 |
Correct |
9 ms |
14412 KB |
Output is correct |
21 |
Correct |
11 ms |
14540 KB |
Output is correct |
22 |
Correct |
10 ms |
14504 KB |
Output is correct |
23 |
Correct |
15 ms |
14484 KB |
Output is correct |
24 |
Correct |
15 ms |
14532 KB |
Output is correct |
25 |
Correct |
27 ms |
15008 KB |
Output is correct |
26 |
Correct |
25 ms |
14924 KB |
Output is correct |
27 |
Correct |
25 ms |
14924 KB |
Output is correct |
28 |
Correct |
25 ms |
15028 KB |
Output is correct |
29 |
Correct |
18 ms |
14744 KB |
Output is correct |
30 |
Correct |
41 ms |
15616 KB |
Output is correct |
31 |
Correct |
43 ms |
15556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
9 ms |
14412 KB |
Output is correct |
3 |
Correct |
9 ms |
14400 KB |
Output is correct |
4 |
Correct |
9 ms |
14412 KB |
Output is correct |
5 |
Correct |
9 ms |
14412 KB |
Output is correct |
6 |
Correct |
9 ms |
14476 KB |
Output is correct |
7 |
Correct |
9 ms |
14412 KB |
Output is correct |
8 |
Correct |
9 ms |
14380 KB |
Output is correct |
9 |
Correct |
9 ms |
14412 KB |
Output is correct |
10 |
Correct |
11 ms |
14540 KB |
Output is correct |
11 |
Correct |
10 ms |
14504 KB |
Output is correct |
12 |
Correct |
10 ms |
14412 KB |
Output is correct |
13 |
Correct |
9 ms |
14412 KB |
Output is correct |
14 |
Correct |
9 ms |
14400 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
9 ms |
14412 KB |
Output is correct |
17 |
Correct |
9 ms |
14476 KB |
Output is correct |
18 |
Correct |
9 ms |
14412 KB |
Output is correct |
19 |
Correct |
9 ms |
14380 KB |
Output is correct |
20 |
Correct |
9 ms |
14412 KB |
Output is correct |
21 |
Correct |
11 ms |
14540 KB |
Output is correct |
22 |
Correct |
10 ms |
14504 KB |
Output is correct |
23 |
Correct |
15 ms |
14484 KB |
Output is correct |
24 |
Correct |
15 ms |
14532 KB |
Output is correct |
25 |
Correct |
27 ms |
15008 KB |
Output is correct |
26 |
Correct |
25 ms |
14924 KB |
Output is correct |
27 |
Correct |
25 ms |
14924 KB |
Output is correct |
28 |
Correct |
25 ms |
15028 KB |
Output is correct |
29 |
Correct |
18 ms |
14744 KB |
Output is correct |
30 |
Correct |
41 ms |
15616 KB |
Output is correct |
31 |
Correct |
43 ms |
15556 KB |
Output is correct |
32 |
Correct |
310 ms |
17500 KB |
Output is correct |
33 |
Correct |
331 ms |
18060 KB |
Output is correct |
34 |
Correct |
552 ms |
26604 KB |
Output is correct |
35 |
Correct |
608 ms |
29920 KB |
Output is correct |
36 |
Correct |
660 ms |
29808 KB |
Output is correct |
37 |
Correct |
610 ms |
29740 KB |
Output is correct |
38 |
Correct |
351 ms |
17476 KB |
Output is correct |
39 |
Correct |
313 ms |
18136 KB |
Output is correct |
40 |
Correct |
351 ms |
25108 KB |
Output is correct |
41 |
Correct |
603 ms |
31436 KB |
Output is correct |
42 |
Correct |
735 ms |
35856 KB |
Output is correct |
43 |
Correct |
755 ms |
36092 KB |
Output is correct |
44 |
Correct |
9 ms |
14412 KB |
Output is correct |
45 |
Correct |
9 ms |
14412 KB |
Output is correct |