#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];
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);
s.insert(a);
}
for(int i=1;i<=n;i++) {
sort(in[i].begin(),in[i].end());
}
for(int i=1;i<=n;i++) {
int mini;
if (in[i].empty()) {
mini=i-1;
}
else {
mini=in[i][0]-1;
}
if (i!=1)
update(0,mini,1);
for(int j=0;j<in[i].size();j++) {
s.erase(s.find(in[i][j]));
}
int en;
if (!s.empty()) {
en=(*s.begin())-1;
}
else {
en=i-1;
}
int val=sum(0,min(en,i-1));
update(i,i,val);
}
printf("%d",sum(n,n));
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int j=0;j<in[i].size();j++) {
| ~^~~~~~~~~~~~~
Main.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%d %d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
5068 KB |
Output is correct |
4 |
Correct |
4 ms |
5068 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
5068 KB |
Output is correct |
4 |
Correct |
4 ms |
5068 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
5068 KB |
Output is correct |
4 |
Correct |
4 ms |
5068 KB |
Output is correct |
5 |
Correct |
4 ms |
5068 KB |
Output is correct |
6 |
Correct |
4 ms |
5068 KB |
Output is correct |
7 |
Correct |
4 ms |
5068 KB |
Output is correct |
8 |
Correct |
4 ms |
5068 KB |
Output is correct |
9 |
Incorrect |
4 ms |
5068 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |