Submission #202010

# Submission time Handle Problem Language Result Execution time Memory
202010 2020-02-13T03:40:54 Z Segtree Bubble Sort 2 (JOI18_bubblesort2) C++14
17 / 100
356 ms 760 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include"bubblesort2.h"
using namespace std;
typedef int ll;
typedef vector<ll> vll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 4010
ll dat[2*N];
void init(){
    rep(i,2*N)dat[i]=0;
}
void upd(ll i,ll x){
    i+=N;
    dat[i]+=x;
    for(;i;i>>=1)dat[i/2]=dat[i]+dat[i^1];
}
ll qry(ll l,ll r){
    l+=N,r+=N+1;
    ll res=0;
    for(ll a=l,b=r;a<b;a>>=1,b>>=1){
	if(a&1)res+=dat[a++];
	if(b&1)res+=dat[--b];
    }
    return res;
}

ll solve(vll a){
    //for(auto t:a)cout<<t<<" ";cout<<endl;
    ll n=a.size(),ans=0;
    init();
    for(int i=0;i<n;i++){
	chmax(ans,qry(a[i]+1,N-1));
	upd(a[i],1);
    }
    return ans;
}
vll countScans(vll a,vll x,vll v){
    ll n=a.size(),q=x.size();
    if(n>2000)return a;
    vll zs;
    for(auto t:a)zs.push_back(t);
    for(auto t:v)zs.push_back(t);
    sort(all(zs));
    zs.erase(unique(all(zs)),zs.end());
    for(int i=0;i<a.size();i++)a[i]=lower_bound(all(zs),a[i])-zs.begin();
    for(int i=0;i<v.size();i++)v[i]=lower_bound(all(zs),v[i])-zs.begin();
    vll fans;
    rep(k,q){
	a[x[k]]=v[k];
	fans.push_back(solve(a));
    }
    return fans;
}
/*int main(){
    ll n,q;
    cin>>n>>q;
    vll a(n),x(q),v(q);
    rep(i,n)cin>>a[i];
    rep(i,q)cin>>x[i]>>v[i];
    vll res=countScans(a,x,v);
    for(auto t:res)cout<<t<<endl;
}*/


Compilation message

bubblesort2.cpp: In function 'vll countScans(vll, vll, vll)':
bubblesort2.cpp:56:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<a.size();i++)a[i]=lower_bound(all(zs),a[i])-zs.begin();
                 ~^~~~~~~~~
bubblesort2.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++)v[i]=lower_bound(all(zs),v[i])-zs.begin();
                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 376 KB Output is correct
2 Correct 64 ms 376 KB Output is correct
3 Correct 342 ms 504 KB Output is correct
4 Correct 356 ms 632 KB Output is correct
5 Correct 341 ms 504 KB Output is correct
6 Correct 299 ms 760 KB Output is correct
7 Correct 307 ms 632 KB Output is correct
8 Correct 313 ms 508 KB Output is correct
9 Correct 331 ms 632 KB Output is correct
10 Correct 317 ms 504 KB Output is correct
11 Correct 316 ms 504 KB Output is correct
12 Correct 303 ms 504 KB Output is correct
13 Correct 312 ms 632 KB Output is correct
14 Correct 312 ms 504 KB Output is correct
15 Correct 313 ms 632 KB Output is correct
16 Correct 303 ms 504 KB Output is correct
17 Correct 319 ms 504 KB Output is correct
18 Correct 308 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 376 KB Output is correct
2 Correct 64 ms 376 KB Output is correct
3 Correct 342 ms 504 KB Output is correct
4 Correct 356 ms 632 KB Output is correct
5 Correct 341 ms 504 KB Output is correct
6 Correct 299 ms 760 KB Output is correct
7 Correct 307 ms 632 KB Output is correct
8 Correct 313 ms 508 KB Output is correct
9 Correct 331 ms 632 KB Output is correct
10 Correct 317 ms 504 KB Output is correct
11 Correct 316 ms 504 KB Output is correct
12 Correct 303 ms 504 KB Output is correct
13 Correct 312 ms 632 KB Output is correct
14 Correct 312 ms 504 KB Output is correct
15 Correct 313 ms 632 KB Output is correct
16 Correct 303 ms 504 KB Output is correct
17 Correct 319 ms 504 KB Output is correct
18 Correct 308 ms 408 KB Output is correct
19 Incorrect 10 ms 760 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 376 KB Output is correct
2 Correct 64 ms 376 KB Output is correct
3 Correct 342 ms 504 KB Output is correct
4 Correct 356 ms 632 KB Output is correct
5 Correct 341 ms 504 KB Output is correct
6 Correct 299 ms 760 KB Output is correct
7 Correct 307 ms 632 KB Output is correct
8 Correct 313 ms 508 KB Output is correct
9 Correct 331 ms 632 KB Output is correct
10 Correct 317 ms 504 KB Output is correct
11 Correct 316 ms 504 KB Output is correct
12 Correct 303 ms 504 KB Output is correct
13 Correct 312 ms 632 KB Output is correct
14 Correct 312 ms 504 KB Output is correct
15 Correct 313 ms 632 KB Output is correct
16 Correct 303 ms 504 KB Output is correct
17 Correct 319 ms 504 KB Output is correct
18 Correct 308 ms 408 KB Output is correct
19 Incorrect 10 ms 760 KB Output isn't correct
20 Halted 0 ms 0 KB -