Submission #210917

# Submission time Handle Problem Language Result Execution time Memory
210917 2020-03-19T02:19:37 Z casperwang Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2511 ms 62500 KB
#include <bits/stdc++.h>
#include <bubblesort2.h>
#define int long long
#define pb push_back
using namespace std;

const int MAXN = 500000;
const int K = 10000000;
int n, q;
int a[MAXN*2+5];
int cpy[MAXN*2+5];

class Seg{
private:
  int arr[MAXN*2*4+5];
  int tag[MAXN*2*4+5];
  void pull(int now) {
    arr[now] = max(arr[now*2], arr[now*2+1]);
  }
  void push(int now, int len) {
    if (!tag[now]) return;
    arr[now] += tag[now];
    if (len > 1) {
      tag[now*2  ] += tag[now];
      tag[now*2+1] += tag[now];
    }
    tag[now] = 0;
  }
public:
  void build(int now=1, int l=1, int r=MAXN*2) {
    tag[now] = 0;
    if (l == r) {
      arr[now] = 0;
      return;
    }
    int mid = (l + r) >> 1;
    build(now*2  , l, mid);
    build(now*2+1,mid+1,r);
    pull(now);
    return;
  }
  void mdy(int ml, int mr, int k, int now=1, int l=1, int r=MAXN*2) {
    push(now, r-l+1);
    if (l >= ml && r <= mr) {
      tag[now] += k;
      push(now, r-l+1);
      return;
    } else if (l > mr || r < ml) return;
    int mid = (l + r) >> 1;
    mdy(ml, mr, k, now*2  , l, mid);
    mdy(ml, mr, k, now*2+1,mid+1,r);
    pull(now);
  }
  int qry(int ql, int qr, int now=1, int l=1, int r=MAXN*2) {
    push(now, r-l+1);
    if (l >= ql && r <= qr) {
      return arr[now];
    } else if (l > qr || r < ql) return -MAXN*2;
    int mid = (l + r) >> 1, tmp = -MAXN*2;
    tmp = max(tmp, qry(ql, qr, now*2  , l, mid));
    tmp = max(tmp, qry(ql, qr, now*2+1,mid+1,r));
    pull(now);
    return tmp;
  }
} seg;

vector <signed> countScans(vector <signed> A, vector <signed> X, vector <signed> Y) {
  int n = A.size(), q = Y.size();
  for (int i = 0; i < n; i++)
    cpy[i] = A[i] * K + i;
  for (int i = 0; i < q; i++)
    cpy[i+n] = Y[i] * K + X[i];
  sort(cpy, cpy+n+q);
  seg.build();
  for (int i = 0; i < n; i++) {
    A[i] = lower_bound(cpy, cpy+n+q, A[i] * K + i) - cpy + 1;
    seg.mdy(A[i], A[i], i);
    seg.mdy(A[i]+1, n+q, -1);
  }
  vector <signed> ans;
  for (int i = 0; i < q; i++) {
    Y[i] = lower_bound(cpy, cpy+n+q, Y[i] * K + X[i]) - cpy + 1;
    seg.mdy(A[X[i]], A[X[i]], -X[i]);
    seg.mdy(A[X[i]]+1, n+q, 1);
    seg.mdy(Y[i], Y[i], X[i]);
    seg.mdy(Y[i]+1, n+q, -1);
    A[X[i]] = Y[i];
    ans.pb(seg.qry(1, MAXN*2));
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 33152 KB Output is correct
2 Correct 24 ms 33280 KB Output is correct
3 Correct 27 ms 33280 KB Output is correct
4 Correct 27 ms 33280 KB Output is correct
5 Correct 29 ms 33272 KB Output is correct
6 Correct 29 ms 33280 KB Output is correct
7 Correct 29 ms 33280 KB Output is correct
8 Correct 30 ms 33280 KB Output is correct
9 Correct 30 ms 33280 KB Output is correct
10 Correct 28 ms 33280 KB Output is correct
11 Correct 27 ms 33280 KB Output is correct
12 Correct 27 ms 33280 KB Output is correct
13 Correct 27 ms 33280 KB Output is correct
14 Correct 26 ms 33280 KB Output is correct
15 Correct 30 ms 33280 KB Output is correct
16 Correct 31 ms 33280 KB Output is correct
17 Correct 31 ms 33280 KB Output is correct
18 Correct 26 ms 33280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 33152 KB Output is correct
2 Correct 24 ms 33280 KB Output is correct
3 Correct 27 ms 33280 KB Output is correct
4 Correct 27 ms 33280 KB Output is correct
5 Correct 29 ms 33272 KB Output is correct
6 Correct 29 ms 33280 KB Output is correct
7 Correct 29 ms 33280 KB Output is correct
8 Correct 30 ms 33280 KB Output is correct
9 Correct 30 ms 33280 KB Output is correct
10 Correct 28 ms 33280 KB Output is correct
11 Correct 27 ms 33280 KB Output is correct
12 Correct 27 ms 33280 KB Output is correct
13 Correct 27 ms 33280 KB Output is correct
14 Correct 26 ms 33280 KB Output is correct
15 Correct 30 ms 33280 KB Output is correct
16 Correct 31 ms 33280 KB Output is correct
17 Correct 31 ms 33280 KB Output is correct
18 Correct 26 ms 33280 KB Output is correct
19 Correct 44 ms 33664 KB Output is correct
20 Correct 46 ms 33792 KB Output is correct
21 Correct 46 ms 33912 KB Output is correct
22 Correct 49 ms 33784 KB Output is correct
23 Correct 47 ms 33784 KB Output is correct
24 Correct 44 ms 33784 KB Output is correct
25 Correct 47 ms 33784 KB Output is correct
26 Correct 45 ms 33784 KB Output is correct
27 Correct 43 ms 33784 KB Output is correct
28 Correct 45 ms 33760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 33660 KB Output is correct
2 Correct 116 ms 34552 KB Output is correct
3 Correct 191 ms 35576 KB Output is correct
4 Correct 194 ms 35612 KB Output is correct
5 Correct 187 ms 35448 KB Output is correct
6 Correct 186 ms 35576 KB Output is correct
7 Correct 205 ms 35448 KB Output is correct
8 Correct 197 ms 35576 KB Output is correct
9 Correct 187 ms 35652 KB Output is correct
10 Correct 177 ms 35576 KB Output is correct
11 Correct 173 ms 35576 KB Output is correct
12 Correct 162 ms 35448 KB Output is correct
13 Correct 162 ms 35576 KB Output is correct
14 Correct 170 ms 35576 KB Output is correct
15 Correct 160 ms 35448 KB Output is correct
16 Correct 158 ms 35576 KB Output is correct
17 Correct 171 ms 35576 KB Output is correct
18 Correct 161 ms 35448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 33152 KB Output is correct
2 Correct 24 ms 33280 KB Output is correct
3 Correct 27 ms 33280 KB Output is correct
4 Correct 27 ms 33280 KB Output is correct
5 Correct 29 ms 33272 KB Output is correct
6 Correct 29 ms 33280 KB Output is correct
7 Correct 29 ms 33280 KB Output is correct
8 Correct 30 ms 33280 KB Output is correct
9 Correct 30 ms 33280 KB Output is correct
10 Correct 28 ms 33280 KB Output is correct
11 Correct 27 ms 33280 KB Output is correct
12 Correct 27 ms 33280 KB Output is correct
13 Correct 27 ms 33280 KB Output is correct
14 Correct 26 ms 33280 KB Output is correct
15 Correct 30 ms 33280 KB Output is correct
16 Correct 31 ms 33280 KB Output is correct
17 Correct 31 ms 33280 KB Output is correct
18 Correct 26 ms 33280 KB Output is correct
19 Correct 44 ms 33664 KB Output is correct
20 Correct 46 ms 33792 KB Output is correct
21 Correct 46 ms 33912 KB Output is correct
22 Correct 49 ms 33784 KB Output is correct
23 Correct 47 ms 33784 KB Output is correct
24 Correct 44 ms 33784 KB Output is correct
25 Correct 47 ms 33784 KB Output is correct
26 Correct 45 ms 33784 KB Output is correct
27 Correct 43 ms 33784 KB Output is correct
28 Correct 45 ms 33760 KB Output is correct
29 Correct 60 ms 33660 KB Output is correct
30 Correct 116 ms 34552 KB Output is correct
31 Correct 191 ms 35576 KB Output is correct
32 Correct 194 ms 35612 KB Output is correct
33 Correct 187 ms 35448 KB Output is correct
34 Correct 186 ms 35576 KB Output is correct
35 Correct 205 ms 35448 KB Output is correct
36 Correct 197 ms 35576 KB Output is correct
37 Correct 187 ms 35652 KB Output is correct
38 Correct 177 ms 35576 KB Output is correct
39 Correct 173 ms 35576 KB Output is correct
40 Correct 162 ms 35448 KB Output is correct
41 Correct 162 ms 35576 KB Output is correct
42 Correct 170 ms 35576 KB Output is correct
43 Correct 160 ms 35448 KB Output is correct
44 Correct 158 ms 35576 KB Output is correct
45 Correct 171 ms 35576 KB Output is correct
46 Correct 161 ms 35448 KB Output is correct
47 Correct 697 ms 43760 KB Output is correct
48 Correct 2404 ms 60012 KB Output is correct
49 Correct 2303 ms 61292 KB Output is correct
50 Correct 2256 ms 61420 KB Output is correct
51 Correct 2266 ms 61324 KB Output is correct
52 Correct 2275 ms 61368 KB Output is correct
53 Correct 2278 ms 61328 KB Output is correct
54 Correct 2079 ms 61292 KB Output is correct
55 Correct 2423 ms 61244 KB Output is correct
56 Correct 1952 ms 61188 KB Output is correct
57 Correct 2511 ms 61036 KB Output is correct
58 Correct 2096 ms 61164 KB Output is correct
59 Correct 2174 ms 61932 KB Output is correct
60 Correct 1809 ms 61932 KB Output is correct
61 Correct 2166 ms 61784 KB Output is correct
62 Correct 1907 ms 62248 KB Output is correct
63 Correct 1908 ms 62060 KB Output is correct
64 Correct 1898 ms 62012 KB Output is correct
65 Correct 1728 ms 62168 KB Output is correct
66 Correct 1764 ms 62500 KB Output is correct
67 Correct 1733 ms 62384 KB Output is correct