Submission #741559

# Submission time Handle Problem Language Result Execution time Memory
741559 2023-05-14T10:33:39 Z MarwenElarbi Bubble Sort 2 (JOI18_bubblesort2) C++14
60 / 100
138 ms 42640 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll MOD = 1e9+7;
const int nax = 1e4+5;
const int MAX_VAL = 1e6;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
/*typedef complex<int> Point;
#define X real()
#define Y imag()*/
/*void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}*/
vector<pair<ll,int>> tab(nax);
vi segtree(nax*4);
vi upd(nax*4);
void update(int left,int right,int value,int pos,int l,int r)
{
    if (l>=left&&r<=right){
        upd[pos]+=value;
        segtree[pos]+=value;
        return;
    }
    if (r<=left||l>=right) return;
    int mid=(l+r)/2;
    update(left,right,value,pos*2+1,l,mid);
    update(left,right,value,pos*2+2,mid,r);
    segtree[pos] = max(segtree[pos*2+1],segtree[pos*2+2])+upd[pos];
}
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V){
    int n,q;
    n=A.size();
    q=X.size();
    vi nabba;
    vi check(n+q);
    map<int,int> ind;
    for (int i = 0; i < n; ++i)
    {
        check[i]=A[i];
    }
    for (int i = 0; i < q; ++i)
    {
        check[i+n]=V[i];
    }
    sort(check.begin(),check.end());
    int cur=0;
    for (int i = 0; i < check.size(); ++i)
    {
        if (i==0)  {
            ind[check[i]]=cur;
            cur++;
        }
        else{
            if (check[i]==check[i-1]) {
                continue;
            }
            ind[check[i]]=cur;
            cur++;
        }
    }
    map<int,set<int>> pos;
    for (int i = 0; i < n; ++i)
    {
        pos[ind[A[i]]].insert(i);
        //cout << ind[A[i]]<<endl;
        update(ind[A[i]],cur,-1,0,0,cur);
    }
    for (int i = 0; i < cur; ++i)
    {
        if ((int)pos[i].size()>0){
            update(i,i+1,*pos[i].rbegin()+1,0,0,cur);
        }
    }
    for (int i = 0; i < q; ++i)
    {
        int x=X[i];
        int nw=V[i];
        int lst=A[x];
        A[x]=nw;
        lst=ind[lst];
        nw=ind[nw];
        int lstpos=*pos[lst].rbegin();
        pos[lst].erase(x);
        if ((int)pos[lst].size()>0) update(lst,lst+1,(*pos[lst].rbegin()-lstpos),0,0,cur);
        else update(lst,lst+1,-lstpos-1,0,0,cur);
        update(lst,cur,1,0,0,cur);
        if ((int)pos[nw].size()==0){
            pos[nw].insert(x);
            update(nw,nw+1,x+1,0,0,cur);
        }else{
            lstpos=*pos[nw].rbegin();
            pos[nw].insert(x);
            update(nw,nw+1,(*pos[nw].rbegin()-lstpos),0,0,cur);
        }
        update(nw,cur,-1,0,0,cur);
        nabba.pb(segtree[0]);
        //cout << segtree[0]<<endl;
    }
    return nabba;
}
/*int readInt(){
    int i;
    if(scanf("%d",&i)!=1){
        fprintf(stderr,"Error while reading input\n");
        exit(1);
    }
    return i;
}
/*int main(){
    optimise;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    //setIO("cowland");
    
}*/
/*int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int N,Q;
    N=readInt();
    Q=readInt();
    
    std::vector<int> A(N);
    for(int i=0;i<N;i++)
        A[i]=readInt();
    
    std::vector<int> X(Q),V(Q);
    for(int j=0;j<Q;j++){
        X[j]=readInt();
        V[j]=readInt();
    }
    
    std::vector<int> res=countScans(A,X,V);
    
    for(int j=0;j<int(res.size());j++)
        printf("%d\n",res[j]);
}*/

Compilation message

bubblesort2.cpp:135:1: warning: "/*" within comment [-Wcomment]
  135 | /*int main(){
      |  
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (int i = 0; i < check.size(); ++i)
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 8 ms 1548 KB Output is correct
4 Correct 7 ms 1492 KB Output is correct
5 Correct 8 ms 1560 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 7 ms 1572 KB Output is correct
8 Correct 7 ms 1564 KB Output is correct
9 Correct 8 ms 1500 KB Output is correct
10 Correct 7 ms 1492 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 7 ms 1496 KB Output is correct
13 Correct 7 ms 1460 KB Output is correct
14 Correct 7 ms 1364 KB Output is correct
15 Correct 7 ms 1444 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 7 ms 1364 KB Output is correct
18 Correct 6 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 8 ms 1548 KB Output is correct
4 Correct 7 ms 1492 KB Output is correct
5 Correct 8 ms 1560 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 7 ms 1572 KB Output is correct
8 Correct 7 ms 1564 KB Output is correct
9 Correct 8 ms 1500 KB Output is correct
10 Correct 7 ms 1492 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 7 ms 1496 KB Output is correct
13 Correct 7 ms 1460 KB Output is correct
14 Correct 7 ms 1364 KB Output is correct
15 Correct 7 ms 1444 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 7 ms 1364 KB Output is correct
18 Correct 6 ms 1364 KB Output is correct
19 Correct 29 ms 3508 KB Output is correct
20 Correct 33 ms 3944 KB Output is correct
21 Correct 32 ms 3876 KB Output is correct
22 Correct 31 ms 3860 KB Output is correct
23 Correct 30 ms 3584 KB Output is correct
24 Correct 30 ms 3596 KB Output is correct
25 Correct 27 ms 3508 KB Output is correct
26 Correct 27 ms 3452 KB Output is correct
27 Correct 27 ms 3316 KB Output is correct
28 Correct 26 ms 3324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2476 KB Output is correct
2 Correct 55 ms 3952 KB Output is correct
3 Correct 97 ms 5184 KB Output is correct
4 Correct 99 ms 5184 KB Output is correct
5 Correct 99 ms 5168 KB Output is correct
6 Correct 91 ms 5156 KB Output is correct
7 Correct 91 ms 5116 KB Output is correct
8 Correct 107 ms 5200 KB Output is correct
9 Correct 92 ms 5188 KB Output is correct
10 Correct 80 ms 5172 KB Output is correct
11 Correct 78 ms 5148 KB Output is correct
12 Correct 84 ms 5180 KB Output is correct
13 Correct 77 ms 5120 KB Output is correct
14 Correct 72 ms 5156 KB Output is correct
15 Correct 73 ms 5188 KB Output is correct
16 Correct 66 ms 5200 KB Output is correct
17 Correct 68 ms 5196 KB Output is correct
18 Correct 72 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 980 KB Output is correct
2 Correct 3 ms 1108 KB Output is correct
3 Correct 8 ms 1548 KB Output is correct
4 Correct 7 ms 1492 KB Output is correct
5 Correct 8 ms 1560 KB Output is correct
6 Correct 8 ms 1492 KB Output is correct
7 Correct 7 ms 1572 KB Output is correct
8 Correct 7 ms 1564 KB Output is correct
9 Correct 8 ms 1500 KB Output is correct
10 Correct 7 ms 1492 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 7 ms 1496 KB Output is correct
13 Correct 7 ms 1460 KB Output is correct
14 Correct 7 ms 1364 KB Output is correct
15 Correct 7 ms 1444 KB Output is correct
16 Correct 6 ms 1364 KB Output is correct
17 Correct 7 ms 1364 KB Output is correct
18 Correct 6 ms 1364 KB Output is correct
19 Correct 29 ms 3508 KB Output is correct
20 Correct 33 ms 3944 KB Output is correct
21 Correct 32 ms 3876 KB Output is correct
22 Correct 31 ms 3860 KB Output is correct
23 Correct 30 ms 3584 KB Output is correct
24 Correct 30 ms 3596 KB Output is correct
25 Correct 27 ms 3508 KB Output is correct
26 Correct 27 ms 3452 KB Output is correct
27 Correct 27 ms 3316 KB Output is correct
28 Correct 26 ms 3324 KB Output is correct
29 Correct 16 ms 2476 KB Output is correct
30 Correct 55 ms 3952 KB Output is correct
31 Correct 97 ms 5184 KB Output is correct
32 Correct 99 ms 5184 KB Output is correct
33 Correct 99 ms 5168 KB Output is correct
34 Correct 91 ms 5156 KB Output is correct
35 Correct 91 ms 5116 KB Output is correct
36 Correct 107 ms 5200 KB Output is correct
37 Correct 92 ms 5188 KB Output is correct
38 Correct 80 ms 5172 KB Output is correct
39 Correct 78 ms 5148 KB Output is correct
40 Correct 84 ms 5180 KB Output is correct
41 Correct 77 ms 5120 KB Output is correct
42 Correct 72 ms 5156 KB Output is correct
43 Correct 73 ms 5188 KB Output is correct
44 Correct 66 ms 5200 KB Output is correct
45 Correct 68 ms 5196 KB Output is correct
46 Correct 72 ms 5208 KB Output is correct
47 Runtime error 138 ms 42640 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -