Submission #570164

# Submission time Handle Problem Language Result Execution time Memory
570164 2022-05-28T19:50:32 Z MohammadAghil Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
4547 ms 106252 KB
      #include <bits/stdc++.h>
      #include "bubblesort2.h"
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) x.begin(), x.end()
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 1e6 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

int seg[maxn<<2], laz[maxn<<2];
map<pp, int> mp; int id;

void updNode(int x, int k){
     seg[x] += k, laz[x] += k;
}

void shift(int x){
     if(laz[x]){
          updNode(x<<1, laz[x]), updNode(x<<1|1, laz[x]);
          laz[x] = 0;
     }
}

void upd(int l, int r, int k, int x = 1, int lx = 0, int rx = id){
     if(l <= lx && r >= rx){
          updNode(x, k);
          return;
     } if(l >= rx || r <= lx) return;
     shift(x);
     int mid = (lx + rx)>>1;
     upd(l, r, k, x<<1, lx, mid), upd(l, r, k, x<<1|1, mid, rx);
     seg[x] = max(seg[x<<1], seg[x<<1|1]);
}

void add(int p, int v, int k){
     int ps = mp[{v, p}];
     upd(ps, ps + 1, k*(inf+p));
     if(ps+1-id) upd(ps+1, id, -k);
}

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
     int n = sz(A), q = sz(X);
     rep(i,0,n) mp[{A[i], i}] = 0;
     rep(i,0,q) mp[{V[i], X[i]}] = 0;
     for(auto&c:mp) c.ss = id++;
     upd(0, id, -inf);
     rep(i,0,n) add(i, A[i], 1);
     vector<int> res(q);
     rep(i,0,q){
          add(X[i], A[X[i]], -1), add(X[i], A[X[i]] = V[i], 1);
          res[i] = seg[1];
     }
     return res;
}

// int main(){
//      cin.tie(0) -> sync_with_stdio(0);
//      int n, q; cin >> n >> q;
//      vector<int> a(n);
//      rep(i,0,n) cin >> a[i], mp[{a[i], i}] = 0;
//      vector<pp> query(q);
//      rep(i,0,q) cin >> query[i].ff >> query[i].ss, mp[{query[i].ss, query[i].ff}] = 0;
//      for(auto&c:mp) c.ss = id++;
//      upd(0, id, -inf);
//      rep(i,0,n) add(i, a[i], 1);
//      for(auto[p, v]: query){
//           add(p, a[p], -1), add(p, a[p] = v, 1);
//           cout << seg[1] << '\n';
//      }
//      return 0; 
// }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 4 ms 688 KB Output is correct
7 Correct 5 ms 688 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 8 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 6 ms 596 KB Output is correct
12 Correct 6 ms 596 KB Output is correct
13 Correct 7 ms 596 KB Output is correct
14 Correct 6 ms 644 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 4 ms 688 KB Output is correct
7 Correct 5 ms 688 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 8 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 6 ms 596 KB Output is correct
12 Correct 6 ms 596 KB Output is correct
13 Correct 7 ms 596 KB Output is correct
14 Correct 6 ms 644 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 19 ms 1620 KB Output is correct
20 Correct 21 ms 1784 KB Output is correct
21 Correct 19 ms 1800 KB Output is correct
22 Correct 21 ms 1776 KB Output is correct
23 Correct 19 ms 1620 KB Output is correct
24 Correct 20 ms 1708 KB Output is correct
25 Correct 18 ms 1620 KB Output is correct
26 Correct 20 ms 1644 KB Output is correct
27 Correct 23 ms 1492 KB Output is correct
28 Correct 17 ms 1544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2920 KB Output is correct
2 Correct 100 ms 6136 KB Output is correct
3 Correct 225 ms 9956 KB Output is correct
4 Correct 209 ms 9980 KB Output is correct
5 Correct 249 ms 9828 KB Output is correct
6 Correct 228 ms 9928 KB Output is correct
7 Correct 189 ms 9864 KB Output is correct
8 Correct 204 ms 9836 KB Output is correct
9 Correct 190 ms 9880 KB Output is correct
10 Correct 128 ms 6108 KB Output is correct
11 Correct 133 ms 6004 KB Output is correct
12 Correct 154 ms 6104 KB Output is correct
13 Correct 117 ms 6132 KB Output is correct
14 Correct 126 ms 6084 KB Output is correct
15 Correct 128 ms 6020 KB Output is correct
16 Correct 117 ms 6240 KB Output is correct
17 Correct 114 ms 6024 KB Output is correct
18 Correct 112 ms 6220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 5 ms 592 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 4 ms 688 KB Output is correct
7 Correct 5 ms 688 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 8 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 6 ms 596 KB Output is correct
12 Correct 6 ms 596 KB Output is correct
13 Correct 7 ms 596 KB Output is correct
14 Correct 6 ms 644 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 19 ms 1620 KB Output is correct
20 Correct 21 ms 1784 KB Output is correct
21 Correct 19 ms 1800 KB Output is correct
22 Correct 21 ms 1776 KB Output is correct
23 Correct 19 ms 1620 KB Output is correct
24 Correct 20 ms 1708 KB Output is correct
25 Correct 18 ms 1620 KB Output is correct
26 Correct 20 ms 1644 KB Output is correct
27 Correct 23 ms 1492 KB Output is correct
28 Correct 17 ms 1544 KB Output is correct
29 Correct 30 ms 2920 KB Output is correct
30 Correct 100 ms 6136 KB Output is correct
31 Correct 225 ms 9956 KB Output is correct
32 Correct 209 ms 9980 KB Output is correct
33 Correct 249 ms 9828 KB Output is correct
34 Correct 228 ms 9928 KB Output is correct
35 Correct 189 ms 9864 KB Output is correct
36 Correct 204 ms 9836 KB Output is correct
37 Correct 190 ms 9880 KB Output is correct
38 Correct 128 ms 6108 KB Output is correct
39 Correct 133 ms 6004 KB Output is correct
40 Correct 154 ms 6104 KB Output is correct
41 Correct 117 ms 6132 KB Output is correct
42 Correct 126 ms 6084 KB Output is correct
43 Correct 128 ms 6020 KB Output is correct
44 Correct 117 ms 6240 KB Output is correct
45 Correct 114 ms 6024 KB Output is correct
46 Correct 112 ms 6220 KB Output is correct
47 Correct 939 ms 31108 KB Output is correct
48 Correct 3555 ms 86628 KB Output is correct
49 Correct 4159 ms 105952 KB Output is correct
50 Correct 4083 ms 106072 KB Output is correct
51 Correct 4016 ms 105960 KB Output is correct
52 Correct 4547 ms 105960 KB Output is correct
53 Correct 4370 ms 105964 KB Output is correct
54 Correct 3841 ms 106064 KB Output is correct
55 Correct 4253 ms 106136 KB Output is correct
56 Correct 4022 ms 106252 KB Output is correct
57 Correct 4038 ms 106056 KB Output is correct
58 Correct 3914 ms 106096 KB Output is correct
59 Correct 3194 ms 96972 KB Output is correct
60 Correct 3294 ms 97048 KB Output is correct
61 Correct 3223 ms 96852 KB Output is correct
62 Correct 3061 ms 92992 KB Output is correct
63 Correct 3155 ms 93016 KB Output is correct
64 Correct 3125 ms 92856 KB Output is correct
65 Correct 3000 ms 88844 KB Output is correct
66 Correct 2926 ms 88844 KB Output is correct
67 Correct 2900 ms 88920 KB Output is correct