Submission #3996425


Source Code Expand

#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const LL INF = 0x3fffffffff;

int N;
int Q;
int bs[214514];
int dp[214514];

struct LazySeg {
  int size;
  vector<char> has_lazy;
  vector<LL> seg;
  vector<LL> lazy;
  vector<LL> width;
  vector<LL> assi;

  LazySeg(vector<LL> A) {
    int n = A.size();
    size = 1;
    while (size < n) size *= 2;

    seg.resize(size);
    seg.insert(seg.end(), A.begin(), A.end());
    seg.resize(size*2);
    lazy.resize(size*2);
    has_lazy.resize(size*2);
    width.resize(size*2);
    assi.resize(size*2);
    rrep(i, size) {
      seg[i] = min(seg[i*2], seg[i*2+1]);
      width[i] = width[i*2] + width[i*2+1]; 
    }
  }

  void LazyPropagate(int k) {
    if (has_lazy[k]) {
      seg[k] = assi[k];
      if (k < size) {
        has_lazy[k*2] = true;
        has_lazy[k*2+1] = true;
        assi[k*2] = assi[k]; 
        assi[k*2+1] = assi[k];
        lazy[k*2] = 0;
        lazy[k*2+1] = 0;
      }
      has_lazy[k] = false;
    }

    seg[k] += lazy[k];
    if (k < size) {
      lazy[k*2] += lazy[k];
      lazy[k*2+1] += lazy[k];
    }
    lazy[k] = 0;
  }

  void Add(int wishl, int wishr, int k, int watchl, int watchr, LL x) {
    if (wishr <= watchl || watchr <= wishl) {
      LazyPropagate(k);
      return;
    }

    if (wishl <= watchl && watchr <= wishr) {
      lazy[k] += x;
      LazyPropagate(k);
      return;
    }

    LazyPropagate(k);
    int mid = (watchl+watchr)/2;
    Add(wishl, wishr, k*2, watchl, mid, x);
    Add(wishl, wishr, k*2+1, mid, watchr, x);
    seg[k] = min(seg[k*2], seg[k*2+1]);
  }

  void Move(int wishl, int wishr, int k, int watchl, int watchr, LL x) {
    if (wishr <= watchl || watchr <= wishl) {
      LazyPropagate(k);
      return;
    }

    if (wishl <= watchl && watchr <= wishr) {
      has_lazy[k] = true;
      lazy[k] = 0;
      assi[k] = x;
      LazyPropagate(k);
      return;
    }

    LazyPropagate(k);
    int mid = (watchl+watchr)/2;
    Move(wishl, wishr, k*2, watchl, mid, x);
    Move(wishl, wishr, k*2+1, mid, watchr, x);
    seg[k] = min(seg[k*2], seg[k*2+1]);
  }

  void Add(int wishl, int wishr, LL x) {
    return Add(wishl, wishr, 1, 0, size, x);
  }

  void Move(int wishl, int wishr, LL x) {
    return Move(wishl, wishr, 1, 0, size, x);
  }

  LL Get(int wishl, int wishr, int k, int watchl, int watchr) {
    LL lval, rval;

    if (wishr <= watchl || watchr <= wishl) return INF;

    if (wishl <= watchl && watchr <= wishr) {
      LazyPropagate(k);
      return seg[k];
    }

    LazyPropagate(k);
    int mid = (watchl+watchr)/2;
    lval = Get(wishl, wishr, k*2, watchl, mid);
    rval = Get(wishl, wishr, k*2+1, mid, watchr);
    return min(lval, rval);
  }

  LL Get(int wishl, int wishr) {
    return Get(wishl, wishr, 1, 0, size);
  }
};

int main() {
  scanf("%d", &N);
  reps(i, 1, N+1) {
    scanf("%d", &bs[i]);
  }

  scanf("%d", &Q);

  vector<pii> segs;
  rep(i, Q) {
    int l, r;
    scanf("%d%d", &l, &r);
    ++r;
    segs.eb(pii(l, r));
  }
  sort(all(segs), greater<pii>());

  // dp[i][j] := we've processed [1, i).  should fill with 1s [*, j)
  LazySeg seg(vector<LL>(N+10));
  seg.Move(1, N+3, 1, 0, 0, INF/2);
  reps(i, 1, N+1) {
    // dp[i+1][k] <- dp[i][*]
    seg.Move(i, i+1, 1, 0, 0, INF/2);

    while (1) {
      auto s = segs.back();
      if (s.X != i) break;
      segs.pop_back();

      int r = s.Y;
      LL v = seg.Get(0, r, 1, 0, 0);
      seg.Move(r, r+1, 1, 0, 0, v);
    }

    LL x = seg.Get(0, 1, 1, 0, 0);
    LL y = seg.Get(i+1, i+2, 1, 0, 0);
    seg.Move(0, 1, 1, 0, 0, min(x+bs[i], y+!bs[i]));
    if (!bs[i]) {
      seg.Add(i+1, N+3, 1, 0, 0, 1);
    }
  }
  assert(segs.empty());
  printf("%lld\n", seg.Get(0, N+3, 1, 0, 0));
}

Submission Info

Submission Time
Task F - NRE
User potetisensei
Language C++14 (GCC 5.4.1)
Score 0
Code Size 4763 Byte
Status RE
Exec Time 129 ms
Memory 21228 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:153:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &N);
                  ^
./Main.cpp:155:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &bs[i]);
                        ^
./Main.cpp:158:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &Q);
                  ^
./Main.cpp:163:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &l, &r);
                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
WA × 7
WA × 117
RE × 10
Set Name Test Cases
Sample example_0, example_1, example_2, example_3, example_4, example_5, example_6
All cent_0, cent_1, cent_2, cent_3, cent_4, cent_5, cent_6, cent_7, cent_8, cent_9, example_0, example_1, example_2, example_3, example_4, example_5, example_6, full_0, full_1, full_10, full_11, full_12, full_13, full_14, full_15, full_16, full_17, full_18, full_19, full_2, full_3, full_4, full_5, full_6, full_7, full_8, full_9, maxrand_0, maxrand_1, maxrand_10, maxrand_11, maxrand_12, maxrand_13, maxrand_14, maxrand_15, maxrand_16, maxrand_17, maxrand_18, maxrand_19, maxrand_2, maxrand_20, maxrand_21, maxrand_22, maxrand_23, maxrand_24, maxrand_25, maxrand_26, maxrand_27, maxrand_28, maxrand_29, maxrand_3, maxrand_4, maxrand_5, maxrand_6, maxrand_7, maxrand_8, maxrand_9, rand_0, rand_1, rand_10, rand_11, rand_12, rand_13, rand_14, rand_15, rand_16, rand_17, rand_18, rand_19, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9, small_0, small_1, small_2, small_3, small_4, small_5, small_6, small_7, small_8, small_9, smallwidth_0, smallwidth_1, smallwidth_10, smallwidth_11, smallwidth_12, smallwidth_13, smallwidth_14, smallwidth_15, smallwidth_16, smallwidth_17, smallwidth_18, smallwidth_19, smallwidth_2, smallwidth_20, smallwidth_21, smallwidth_22, smallwidth_23, smallwidth_24, smallwidth_25, smallwidth_26, smallwidth_27, smallwidth_28, smallwidth_29, smallwidth_3, smallwidth_4, smallwidth_5, smallwidth_6, smallwidth_7, smallwidth_8, smallwidth_9
Case Name Status Exec Time Memory
cent_0 WA 82 ms 21100 KB
cent_1 WA 81 ms 21100 KB
cent_2 WA 81 ms 21100 KB
cent_3 WA 81 ms 21100 KB
cent_4 WA 82 ms 21100 KB
cent_5 WA 82 ms 21100 KB
cent_6 WA 82 ms 21100 KB
cent_7 WA 82 ms 21100 KB
cent_8 WA 81 ms 21100 KB
cent_9 WA 82 ms 21100 KB
example_0 WA 1 ms 256 KB
example_1 WA 1 ms 256 KB
example_2 WA 1 ms 256 KB
example_3 WA 1 ms 256 KB
example_4 WA 1 ms 256 KB
example_5 WA 1 ms 256 KB
example_6 WA 1 ms 256 KB
full_0 RE 126 ms 19452 KB
full_1 WA 81 ms 21100 KB
full_10 RE 127 ms 19580 KB
full_11 WA 81 ms 21100 KB
full_12 RE 127 ms 19580 KB
full_13 WA 81 ms 21100 KB
full_14 RE 126 ms 19452 KB
full_15 WA 81 ms 21100 KB
full_16 RE 126 ms 19580 KB
full_17 WA 81 ms 21100 KB
full_18 RE 127 ms 19580 KB
full_19 WA 81 ms 21100 KB
full_2 RE 127 ms 19580 KB
full_3 WA 81 ms 21100 KB
full_4 RE 126 ms 19580 KB
full_5 WA 81 ms 21100 KB
full_6 RE 126 ms 19580 KB
full_7 WA 81 ms 21100 KB
full_8 RE 129 ms 19452 KB
full_9 WA 81 ms 21100 KB
maxrand_0 WA 29 ms 19580 KB
maxrand_1 WA 81 ms 21100 KB
maxrand_10 WA 29 ms 19580 KB
maxrand_11 WA 81 ms 21100 KB
maxrand_12 WA 29 ms 19580 KB
maxrand_13 WA 81 ms 21100 KB
maxrand_14 WA 29 ms 19452 KB
maxrand_15 WA 81 ms 21100 KB
maxrand_16 WA 29 ms 19452 KB
maxrand_17 WA 81 ms 21100 KB
maxrand_18 WA 29 ms 19580 KB
maxrand_19 WA 81 ms 21100 KB
maxrand_2 WA 29 ms 19452 KB
maxrand_20 WA 29 ms 19452 KB
maxrand_21 WA 81 ms 21100 KB
maxrand_22 WA 29 ms 19580 KB
maxrand_23 WA 83 ms 21228 KB
maxrand_24 WA 29 ms 19580 KB
maxrand_25 WA 81 ms 21100 KB
maxrand_26 WA 29 ms 19580 KB
maxrand_27 WA 81 ms 21100 KB
maxrand_28 WA 29 ms 19452 KB
maxrand_29 WA 81 ms 21100 KB
maxrand_3 WA 81 ms 21100 KB
maxrand_4 WA 29 ms 19580 KB
maxrand_5 WA 81 ms 21100 KB
maxrand_6 WA 29 ms 19452 KB
maxrand_7 WA 81 ms 21100 KB
maxrand_8 WA 29 ms 19452 KB
maxrand_9 WA 82 ms 21100 KB
rand_0 WA 81 ms 21100 KB
rand_1 WA 43 ms 6512 KB
rand_10 WA 82 ms 21100 KB
rand_11 WA 33 ms 10612 KB
rand_12 WA 81 ms 21100 KB
rand_13 WA 61 ms 19948 KB
rand_14 WA 81 ms 21100 KB
rand_15 WA 35 ms 6132 KB
rand_16 WA 81 ms 21100 KB
rand_17 WA 45 ms 10736 KB
rand_18 WA 81 ms 21100 KB
rand_19 WA 72 ms 20588 KB
rand_2 WA 81 ms 21100 KB
rand_3 WA 59 ms 6896 KB
rand_4 WA 81 ms 21100 KB
rand_5 WA 40 ms 2420 KB
rand_6 WA 81 ms 21100 KB
rand_7 WA 49 ms 11504 KB
rand_8 WA 81 ms 21100 KB
rand_9 WA 29 ms 19064 KB
small_0 WA 1 ms 256 KB
small_1 WA 1 ms 256 KB
small_2 WA 1 ms 256 KB
small_3 WA 1 ms 256 KB
small_4 WA 1 ms 256 KB
small_5 WA 1 ms 256 KB
small_6 WA 1 ms 256 KB
small_7 WA 1 ms 256 KB
small_8 WA 1 ms 256 KB
small_9 WA 1 ms 256 KB
smallwidth_0 WA 29 ms 19580 KB
smallwidth_1 WA 81 ms 21100 KB
smallwidth_10 WA 29 ms 19452 KB
smallwidth_11 WA 80 ms 21100 KB
smallwidth_12 WA 29 ms 19580 KB
smallwidth_13 WA 81 ms 21100 KB
smallwidth_14 WA 29 ms 19452 KB
smallwidth_15 WA 80 ms 21100 KB
smallwidth_16 WA 29 ms 19452 KB
smallwidth_17 WA 81 ms 21100 KB
smallwidth_18 WA 29 ms 19452 KB
smallwidth_19 WA 80 ms 21100 KB
smallwidth_2 WA 29 ms 19580 KB
smallwidth_20 WA 29 ms 19580 KB
smallwidth_21 WA 81 ms 21100 KB
smallwidth_22 WA 29 ms 19452 KB
smallwidth_23 WA 80 ms 21100 KB
smallwidth_24 WA 29 ms 19580 KB
smallwidth_25 WA 81 ms 21100 KB
smallwidth_26 WA 29 ms 19452 KB
smallwidth_27 WA 80 ms 21100 KB
smallwidth_28 WA 29 ms 19452 KB
smallwidth_29 WA 81 ms 21100 KB
smallwidth_3 WA 80 ms 21100 KB
smallwidth_4 WA 29 ms 19452 KB
smallwidth_5 WA 81 ms 21100 KB
smallwidth_6 WA 29 ms 19580 KB
smallwidth_7 WA 80 ms 21100 KB
smallwidth_8 WA 29 ms 19580 KB
smallwidth_9 WA 81 ms 21100 KB