답안 #412551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412551 2021-05-27T05:58:56 Z 조영욱(#7650) Bread First Search (CCO21_day2problem2) C++17
0 / 25
5 ms 5068 KB
#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);
        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:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         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);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Incorrect 4 ms 5004 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Incorrect 4 ms 5004 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Incorrect 4 ms 5004 KB Output isn't correct
5 Halted 0 ms 0 KB -