답안 #210806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210806 2020-03-18T11:16:47 Z eric_xiao Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
86 ms 2800 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>
#define ll long long
#define MOD 10000000007
using namespace std;
int N,Q,sz;
int ST[6000009],tag[6000009];
void push(int p,int l,int r)
{
    if(r == l+1) return;
    tag[p*2] += tag[p];
    tag[p*2+1] += tag[p];
    ST[p*2] += tag[p];
    ST[p*2+1] += tag[p];
    tag[p] = 0;
    return;
}
void Build(int p,int l,int r)
{
    ST[p] = 0;
    if(r == l + 1) return;
    int mid = (l + r)/2;
    Build(p*2,l,mid);
    Build(p*2+1,mid,r);
}
void Modify(int p,int l,int r,int ql,int qr,int k)
{
    if(l >= ql && r <= qr)
    {
        tag[p] += k;
        ST[p] += k;
        return;
    }
    if(l >= qr || r <= ql) return;
    push(p,l,r);
    int mid = (l + r)/2;
    Modify(p*2,l,mid,ql,qr,k);
    Modify(p*2+1,mid,r,ql,qr,k);
    ST[p] = max(ST[p*2+1],ST[p*2]);
}

vector<int> countScans(vector<int> A,vector<int> X,vector<int> V)
{
    int i;
    vector<int> ans;
    N = A.size();
    Q = X.size();
    vector<ll> v;
    for(i = 0;i < N;i++) v.push_back((ll)A[i]*(ll)MOD + (ll)i);
    for(i = 0;i < Q;i++) v.push_back((ll)V[i]*(ll)MOD + (ll)i);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    sz = v.size() + 5;
    for(i = 0;i < N;i++)
    {
        A[i] = lower_bound(v.begin(),v.end(),(ll)A[i]*(ll)MOD + (ll)i) - v.begin() + 1;
    }
    for(i = 0;i < Q;i++)
    {
        V[i] = lower_bound(v.begin(),v.end(),(ll)V[i]*(ll)MOD + (ll)i) - v.begin() + 1;
    }
    Build(1,0,sz);
    for(i = 0;i < N;i++)
    {
        Modify(1,0,sz,A[i],A[i]+1,i);
    }
    for(i = 0;i < N;i++)
    {
        Modify(1,0,sz,A[i]+1,sz,-1);
    }
    for(i = 0;i < Q;i++)
    {
        int x = X[i],v = V[i];
        Modify(1,0,sz,A[x]+1,sz,1);
        Modify(1,0,sz,v+1,sz,-1);
        Modify(1,0,sz,A[x],A[x]+1,-x);
        Modify(1,0,sz,v,v+1,x);
        A[x] = v;
        //cout << ST[1] << endl;
        ans.push_back(ST[1]);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 11 ms 632 KB Output is correct
4 Correct 9 ms 504 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 9 ms 504 KB Output is correct
7 Correct 10 ms 504 KB Output is correct
8 Correct 9 ms 504 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 10 ms 504 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 9 ms 632 KB Output is correct
13 Correct 11 ms 632 KB Output is correct
14 Correct 9 ms 504 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
16 Correct 9 ms 504 KB Output is correct
17 Correct 9 ms 552 KB Output is correct
18 Correct 12 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 11 ms 632 KB Output is correct
4 Correct 9 ms 504 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 9 ms 504 KB Output is correct
7 Correct 10 ms 504 KB Output is correct
8 Correct 9 ms 504 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 10 ms 504 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 9 ms 632 KB Output is correct
13 Correct 11 ms 632 KB Output is correct
14 Correct 9 ms 504 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
16 Correct 9 ms 504 KB Output is correct
17 Correct 9 ms 552 KB Output is correct
18 Correct 12 ms 504 KB Output is correct
19 Correct 22 ms 1016 KB Output is correct
20 Correct 24 ms 1016 KB Output is correct
21 Correct 24 ms 1016 KB Output is correct
22 Correct 24 ms 1016 KB Output is correct
23 Correct 23 ms 1016 KB Output is correct
24 Correct 23 ms 1016 KB Output is correct
25 Correct 22 ms 1016 KB Output is correct
26 Correct 22 ms 1016 KB Output is correct
27 Correct 22 ms 1016 KB Output is correct
28 Correct 21 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1524 KB Output is correct
2 Incorrect 86 ms 2800 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 11 ms 632 KB Output is correct
4 Correct 9 ms 504 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 9 ms 504 KB Output is correct
7 Correct 10 ms 504 KB Output is correct
8 Correct 9 ms 504 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 10 ms 504 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 9 ms 632 KB Output is correct
13 Correct 11 ms 632 KB Output is correct
14 Correct 9 ms 504 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
16 Correct 9 ms 504 KB Output is correct
17 Correct 9 ms 552 KB Output is correct
18 Correct 12 ms 504 KB Output is correct
19 Correct 22 ms 1016 KB Output is correct
20 Correct 24 ms 1016 KB Output is correct
21 Correct 24 ms 1016 KB Output is correct
22 Correct 24 ms 1016 KB Output is correct
23 Correct 23 ms 1016 KB Output is correct
24 Correct 23 ms 1016 KB Output is correct
25 Correct 22 ms 1016 KB Output is correct
26 Correct 22 ms 1016 KB Output is correct
27 Correct 22 ms 1016 KB Output is correct
28 Correct 21 ms 1016 KB Output is correct
29 Correct 29 ms 1524 KB Output is correct
30 Incorrect 86 ms 2800 KB Output isn't correct
31 Halted 0 ms 0 KB -