Submission #888365

# Submission time Handle Problem Language Result Execution time Memory
888365 2023-12-17T05:22:20 Z 1075508020060209tc Alternating Current (BOI18_alternating) C++14
Compilation error
0 ms 0 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

int n;int m;
pair<pair<int,int>,int>ar[500005];
int freq[500005];
int freq2[500005];


int ans[500005];
int fans[500005];
void chk(){

for(int i=1;i<=m;i++){
    if(ans[i]){
        fans[ar[i].second]=1;
        freq[ar[i].first.first]++;
        freq[ar[i].first.second+1]--;
    }else{
        freq2[ar[i].first.first]++;
        freq2[ar[i].first.second+1]--;
    }
}


for(int i=1;i<=n;i++){
    freq[i]+=freq[i-1];
    freq2[i]+=freq2[i-1];
    if(freq[i]==0||freq2[i]==0){
        cout<<"impossible\n";exit(0);
    }
}

}


signed main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
    cin>>ar[i].first.first;
    cin>>ar[i].first.second;
    ar[i].second=i;
}
sort(ar+1,ar+m+1);
int stx=0;int sty=0;int xrr=1;
priority_queue<pair<int,int>>pq;
vector<int>vca;vector<int>vcb;
ar[m+1]={{n+10,n+10},0};
for(int i=1;i<=m+1;i++){
    pair<int,int>pr=ar[i].first;
    if(pr.first<=stx+1&&pr.second<=sty){
        vca.push_back(i);
        stx=max(stx,pr.second);
        continue;
    }
    if(pr.second<=sty){
        vcb.push_back(i);
        if(pq.size()){
            stx=max(stx,pq.top().first);
            vca.push_back(pq.top().second);
            pq.pop();
            if(stx>sty){
                swap(stx,sty);
                swap(vca,vcb);
            }
        }else{
            cout<<"impossible\n";return 0;
        }
        continue;
    }
    if(pr.first>stx+1){
        sty=max(sty,pr.second);
        vcb.push_back(i);
        continue;
    }
    pq.push({pr.second,i});
}
while(pq.size()){
    vca.push_back(pq.top());
    pq.pop();
}

for(int i=0;i<vca.size();i++){
    ans[vca[i]]=1;
}
chk();
for(int i=1;i<=m;i++){
    cout<<fans[i];
}



}

Compilation message

alternating.cpp: In function 'int main()':
alternating.cpp:80:27: error: no matching function for call to 'std::vector<int>::push_back(const value_type&)'
   80 |     vca.push_back(pq.top());
      |                           ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from alternating.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'const value_type' {aka 'const std::pair<int, int>'} to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'const value_type' {aka 'const std::pair<int, int>'} to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
alternating.cpp:84:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 | for(int i=0;i<vca.size();i++){
      |             ~^~~~~~~~~~~
alternating.cpp:46:25: warning: unused variable 'xrr' [-Wunused-variable]
   46 | int stx=0;int sty=0;int xrr=1;
      |                         ^~~