Submission #116582

# Submission time Handle Problem Language Result Execution time Memory
116582 2019-06-13T03:05:09 Z mirbek01 Meetings (IOI18_meetings) C++11
36 / 100
654 ms 196516 KB
# include <bits/stdc++.h>
# include "meetings.h"

using namespace std;

const int N = 8e5 + 2;
const int M = 5e3 + 2;

long long a[M][M], t[N * 4];

void upd(int pos, int val, int v = 1, int tl = 1, int tr = N - 1){
      if(tl == tr)
            t[v] = val;
      else {
            int tm = (tl + tr) >> 1;
            if(pos <= tm)
                  upd(pos, val, v << 1, tl, tm);
            else
                  upd(pos, val, v << 1 | 1, tm + 1, tr);
            t[v] = max(t[v << 1], t[v << 1 | 1]);
      }
}

int get(int l, int r, int v = 1, int tl = 1, int tr = N - 1){
      if(l > tr || tl > r)
            return 0;
      if(l <= tl && tr <= r)
            return t[v];
      int tm = (tl + tr) >> 1;
      return max(get(l, r, v << 1, tl, tm),
                  get(l, r, v << 1 | 1, tm + 1, tr));
}

vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
      int Q = L.size();
      int n = H.size();
      vector<long long> C(Q);
      if(n <= 5000){
            for(int i = 0; i < n; i ++){
                  a[i][i] = H[i];
                  for(int j = i - 1; j >= 0; j --)
                        a[i][j] = max(int(a[i][j + 1]), H[j]);
                  for(int j = i + 1; j < n; j ++)
                        a[i][j] = max(int(a[i][j - 1]), H[j]);
                  for(int j = 1; j < n; j ++)
                        a[i][j] += a[i][j - 1];
            }
            for(int i = 0; i < Q; i ++){
                  long long ret = 5e18;
                  for(int j = L[i]; j <= R[i]; j ++){
                        long long now = a[j][R[i]];
                        if(L[i])
                              now -= a[j][L[i] - 1];
                        ret = min(ret, now);
                  }
                  C[i] = ret;
            }
      } else {
            vector < pair <int, int> > qe;
            qe.push_back({-1, -1});
            int q = 0;
            for(int i = 0; i < n; i ++){
                  if(H[i] == 2)
                        continue;
                  int j = i;
                  while(j + 1 < n && H[j + 1] == 1)
                        j ++;
                  qe.push_back({i, j});
                  upd(++ q, j - i + 1);
                  i = j;
            }

            for(int i = 0; i < Q; i ++){
                  C[i] = (R[i] - L[i] + 1) * 2;
                  int mx = 0;
                  int lo = 1, hi = q;
                  while(hi - lo > 1){
                        int md = (lo + hi) >> 1;
                        if(qe[md].second >= L[i])
                              hi = md;
                        else
                              lo = md;
                  }
                  if(qe[lo].second >= L[i])
                        hi = lo;
                  if(qe[hi].second >= L[i] && qe[hi].first <= L[i]){
                        mx = min(qe[hi].second, R[i]) - L[i] + 1;
                  }
                  lo = 1, hi = q;
                  while(hi - lo > 1){
                        int md = (lo + hi) >> 1;
                        if(qe[md].first <= R[i])
                              lo = md;
                        else
                              hi = md;
                  }
                  if(qe[hi].first <= R[i])
                        lo = hi;
                  if(qe[lo].first <= R[i] && R[i] <= qe[lo].second)
                        mx = max(mx, R[i] - max(qe[lo].first, L[i]) + 1);
                  int l, r;
                  lo = 1, hi = q;
                  while(hi - lo > 1){
                        int md = (lo + hi) >> 1;
                        if(qe[md].first >= L[i])
                              hi = md;
                        else
                              lo = md;
                  }
                  if(qe[lo].first >= L[i])
                        hi = lo;
                  if(qe[hi].first < L[i])
                        hi ++;
                  l = hi;
                  lo = 1, hi = q;
                  while(hi - lo > 1){
                        int md = (lo + hi) >> 1;
                        if(qe[md].second <= R[i])
                              lo = md;
                        else
                              hi = md;
                  }
                  if(qe[hi].second <= R[i])
                        lo = hi;
                  if(qe[lo].second > R[i])
                        lo --;
                  r = lo;
                  if(l <= r && 1 <= l && r <= q)
                        mx = max(mx, get(l, r));
                  C[i] -= mx;
            }
      }
      return C;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 95 ms 82800 KB Output is correct
3 Correct 96 ms 82892 KB Output is correct
4 Correct 95 ms 82808 KB Output is correct
5 Correct 96 ms 82776 KB Output is correct
6 Correct 97 ms 82936 KB Output is correct
7 Correct 96 ms 82808 KB Output is correct
8 Correct 103 ms 82808 KB Output is correct
9 Correct 95 ms 82808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 95 ms 82800 KB Output is correct
3 Correct 96 ms 82892 KB Output is correct
4 Correct 95 ms 82808 KB Output is correct
5 Correct 96 ms 82776 KB Output is correct
6 Correct 97 ms 82936 KB Output is correct
7 Correct 96 ms 82808 KB Output is correct
8 Correct 103 ms 82808 KB Output is correct
9 Correct 95 ms 82808 KB Output is correct
10 Correct 515 ms 196348 KB Output is correct
11 Correct 651 ms 196344 KB Output is correct
12 Correct 502 ms 196516 KB Output is correct
13 Correct 654 ms 196344 KB Output is correct
14 Correct 532 ms 196376 KB Output is correct
15 Correct 528 ms 196344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 38 ms 2424 KB Output is correct
3 Correct 110 ms 6260 KB Output is correct
4 Correct 77 ms 5468 KB Output is correct
5 Correct 81 ms 6260 KB Output is correct
6 Correct 57 ms 5496 KB Output is correct
7 Correct 54 ms 5444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 38 ms 2424 KB Output is correct
3 Correct 110 ms 6260 KB Output is correct
4 Correct 77 ms 5468 KB Output is correct
5 Correct 81 ms 6260 KB Output is correct
6 Correct 57 ms 5496 KB Output is correct
7 Correct 54 ms 5444 KB Output is correct
8 Incorrect 169 ms 8124 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 95 ms 82800 KB Output is correct
3 Correct 96 ms 82892 KB Output is correct
4 Correct 95 ms 82808 KB Output is correct
5 Correct 96 ms 82776 KB Output is correct
6 Correct 97 ms 82936 KB Output is correct
7 Correct 96 ms 82808 KB Output is correct
8 Correct 103 ms 82808 KB Output is correct
9 Correct 95 ms 82808 KB Output is correct
10 Correct 515 ms 196348 KB Output is correct
11 Correct 651 ms 196344 KB Output is correct
12 Correct 502 ms 196516 KB Output is correct
13 Correct 654 ms 196344 KB Output is correct
14 Correct 532 ms 196376 KB Output is correct
15 Correct 528 ms 196344 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 38 ms 2424 KB Output is correct
18 Correct 110 ms 6260 KB Output is correct
19 Correct 77 ms 5468 KB Output is correct
20 Correct 81 ms 6260 KB Output is correct
21 Correct 57 ms 5496 KB Output is correct
22 Correct 54 ms 5444 KB Output is correct
23 Incorrect 169 ms 8124 KB Output isn't correct
24 Halted 0 ms 0 KB -