Submission #1987403


Source Code Expand

// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , a[N] , b[N] , c[N] , has[N];
int s[N] , del[N] , maxup[N];

int main(){
  scanf("%d",&n);
  rep(i,0,n) scanf("%d%d",a+i,b+i);
  rep(i,0,n+1) scanf("%d",c+i);
  vi v(c,c+n+1);
  sort(all(v));
  v.erase(unique(all(v)),v.end());
#define rk(x) lower_bound(all(v),x)-v.begin()
  vi seg;
  rep(i,0,n) {
    a[i]=rk(a[i]);b[i]=rk(b[i]);
    s[a[i]]++;
    if(b[i]<a[i]) {
      has[i] = true;
      seg.pb(i);
    }
  }
  rep(i,0,n+1) {
    c[i]=rk(c[i]);
    s[c[i]]--;
  }
  int need = 0 , err = 0 , cur = 0 , dif = 0;
  sort(all(seg),[&](int x,int y){return a[x]>a[y];});
  rep(i,1,sz(v)) s[i]+=s[i-1];
  priority_queue<pii> Q;
  vi used;
  per(i,0,sz(v)) {
    dif += del[i];
    int t = s[i] + dif;
    while(cur<sz(seg)&&a[seg[cur]]>i) {
      Q.push(mp(-b[seg[cur]],seg[cur]));
      cur++;
    }
    while(t<-1&&sz(Q)) {
      int x = Q.top().se;Q.pop();
      if(b[x]>i) continue;
      used.pb(x);
      has[x] = false;
      need ++;
      dif ++;
      t ++;
      if(b[x]) del[b[x]-1] --;
    }
    if(t<-1) {
      err=1;
      break;
    }
  }
  if(!err) {
    memset(del , 0 , sizeof(del));
    for(auto e : used) del[b[e]]++ , del[a[e]]--;
    rep(i,1,sz(v)) del[i]+=del[i-1];
    rep(i,0,sz(v)) s[i]+=del[i];
    memset(maxup , -1 , sizeof(maxup));
    maxup[0] = n - need;
    vi seg;
    rep(i,0,n) if(has[i]) {
      seg.pb(i);
    }
    sort(all(seg),[&](int x,int y){return b[x]<b[y];});
    priority_queue<pii> Q;
    memset(del , 0 , sizeof(del));
    int cur = 0 , dif = 0;
    rep(i,0,sz(v)) {
      dif += del[i];
      int t = s[i] + dif;
      while(cur<sz(seg)&&b[seg[cur]]<=i){
        Q.push(mp(a[seg[cur]],seg[cur]));
        cur++;
      }
      while(t<0&&sz(Q)) {
        int x = Q.top().se;Q.pop();
        if(a[x]<=i) continue;
        need ++;
        dif ++;
        t ++;
        del[a[x]]--;
      }
      if(t<0) break;
      else maxup[i+1] = n - need;
    }
  } else memset(maxup , -1 , sizeof(maxup));
  int q;
  scanf("%d",&q);
  rep(i,0,q) {
    int d,e;
    scanf("%d%d",&d,&e);
    d=rk(d);e=rk(e);
    int ans=-1;
    if(maxup[d]!=-1) ans=max(ans,maxup[d]+1);
    if(maxup[e]!=-1) ans=max(ans,maxup[e]);
    printf("%d\n",ans);
  }
  return 0;
}

Submission Info

Submission Time
Task F - Two Faced Cards
User Y_UME
Language C++14 (GCC 5.4.1)
Score 2000
Code Size 3100 Byte
Status AC
Exec Time 161 ms
Memory 6772 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:42:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);
                 ^
./Main.cpp:43:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   rep(i,0,n) scanf("%d%d",a+i,b+i);
                                   ^
./Main.cpp:44:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   rep(i,0,n+1) scanf("%d",c+i);
                               ^
./Main.cpp:124:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&q);
                 ^
./Main.cpp:127:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&d,&e);
                 ...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 2000 / 2000
Status
AC × 3
AC × 61
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_30.txt, subtask_1_31.txt, subtask_1_32.txt, subtask_1_33.txt, subtask_1_34.txt, subtask_1_35.txt, subtask_1_36.txt, subtask_1_37.txt, subtask_1_38.txt, subtask_1_39.txt, subtask_1_40.txt, subtask_1_41.txt, subtask_1_42.txt, subtask_1_43.txt, subtask_1_44.txt, subtask_1_45.txt, subtask_1_46.txt, subtask_1_47.txt, subtask_1_48.txt, subtask_1_49.txt, subtask_1_50.txt, subtask_1_51.txt, subtask_1_52.txt, subtask_1_53.txt, subtask_1_54.txt, subtask_1_55.txt
Case Name Status Exec Time Memory
sample_01.txt AC 2 ms 1024 KB
sample_02.txt AC 2 ms 1024 KB
sample_03.txt AC 2 ms 1024 KB
subtask_1_01.txt AC 61 ms 3452 KB
subtask_1_02.txt AC 75 ms 3364 KB
subtask_1_03.txt AC 33 ms 2312 KB
subtask_1_04.txt AC 69 ms 4212 KB
subtask_1_05.txt AC 47 ms 2392 KB
subtask_1_06.txt AC 106 ms 3988 KB
subtask_1_07.txt AC 93 ms 3576 KB
subtask_1_08.txt AC 103 ms 4684 KB
subtask_1_09.txt AC 105 ms 5620 KB
subtask_1_10.txt AC 60 ms 3480 KB
subtask_1_11.txt AC 48 ms 2172 KB
subtask_1_12.txt AC 53 ms 2888 KB
subtask_1_13.txt AC 78 ms 3728 KB
subtask_1_14.txt AC 44 ms 2840 KB
subtask_1_15.txt AC 63 ms 2936 KB
subtask_1_16.txt AC 32 ms 1920 KB
subtask_1_17.txt AC 153 ms 6644 KB
subtask_1_18.txt AC 36 ms 2840 KB
subtask_1_19.txt AC 94 ms 2684 KB
subtask_1_20.txt AC 114 ms 4616 KB
subtask_1_21.txt AC 146 ms 5236 KB
subtask_1_22.txt AC 149 ms 5492 KB
subtask_1_23.txt AC 145 ms 5236 KB
subtask_1_24.txt AC 150 ms 5492 KB
subtask_1_25.txt AC 161 ms 6772 KB
subtask_1_26.txt AC 150 ms 5396 KB
subtask_1_27.txt AC 132 ms 3832 KB
subtask_1_28.txt AC 150 ms 5496 KB
subtask_1_29.txt AC 161 ms 6772 KB
subtask_1_30.txt AC 151 ms 5396 KB
subtask_1_31.txt AC 132 ms 3832 KB
subtask_1_32.txt AC 149 ms 5108 KB
subtask_1_33.txt AC 161 ms 6772 KB
subtask_1_34.txt AC 151 ms 5396 KB
subtask_1_35.txt AC 132 ms 3832 KB
subtask_1_36.txt AC 150 ms 5496 KB
subtask_1_37.txt AC 161 ms 6772 KB
subtask_1_38.txt AC 149 ms 5396 KB
subtask_1_39.txt AC 132 ms 3832 KB
subtask_1_40.txt AC 149 ms 5496 KB
subtask_1_41.txt AC 113 ms 4856 KB
subtask_1_42.txt AC 96 ms 3840 KB
subtask_1_43.txt AC 130 ms 6388 KB
subtask_1_44.txt AC 99 ms 3840 KB
subtask_1_45.txt AC 95 ms 3200 KB
subtask_1_46.txt AC 98 ms 4852 KB
subtask_1_47.txt AC 83 ms 3584 KB
subtask_1_48.txt AC 113 ms 6132 KB
subtask_1_49.txt AC 83 ms 3712 KB
subtask_1_50.txt AC 81 ms 3072 KB
subtask_1_51.txt AC 2 ms 1024 KB
subtask_1_52.txt AC 2 ms 1024 KB
subtask_1_53.txt AC 2 ms 1024 KB
subtask_1_54.txt AC 2 ms 1024 KB
subtask_1_55.txt AC 2 ms 1024 KB