Submission #623356

#TimeUsernameProblemLanguageResultExecution timeMemory
623356PanTkdArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
//
//  main.cpp
//
//  Created by Panagiotis Chadjicostas on
//  Copyright © Panagiotis Hadjicostas. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define fo(i,a,b) for(int i = a; i<=b; i++)
#define f(i,b) for(int i=0;i<b;i++)
#define F first
#define S second
#define sz size
#define ls s,m,idx<<1
#define rs m+1,e,idx<<1|1
const ll MOD=ll(1e9)+7;
const ll MAXN=2*ll(1e6);
void checker(){
    ll n=rand()%20+2;
    vi a(n,ll());
    for(ll i=0;i<n;i++){
        a[i]=rand()%20+2;
    }
    for(ll b=0;b<(1<<n);b++){
        vi on,off;
        for(ll i=0;i<n;i++){
            if(i&(1<<i)){
                on.push_back(i);
            }
            else{
                off.push_back(i);
            }
        }
    }
}
///////////////////////////////////////////////////////////////////////

struct shoes{
    int s;
    bool r;
}A[100000];
vector<vi> d(100000,vi()),a(100000,vi());
vi P(100000,ll());

vi seg(100000,0);

void update (ll qs,ll qe,ll s,ll e, ll idx){
    if(s==e){
        seg[idx]^=1;
    }
    if(s>qe||e<qs)return;
    ll m=(s+e)>>1;
    build(qs,qe,ls);
    build(qs,qe,rs);
    seg[idx]=seg[idx<<1]+seg[idx<<1|1];
}
ll query(ll qs,ll qe,ll s,ll e,ll idx){
    if(qs<=s&&e<=qe){
        return seg[idx];
    }
    if(s>qe||e<qs)return 0;
    ll m=(s+e)>>1;
    return query(qs,qe,ls)+query(qs,qe,rs);
}
long long count_swaps(vector <int> S) {
    ll n=S.size();
    for(ll i=0;i<n;i++){
        A[i].s=abs(S[i]);
        A[i].r=(S[i]>0);
        if(A[i].r){
            d[A[i].s].push_back(i);
        }
        else
            a[A[i].s].push_back(i);
    }
    vi V(n,0);
    ll ans=0;
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<a[i].size();j++){
            if(a[i][j]>d[i][j]){
                ans++;
                swap(a[i][j],d[i][j]);
                A[a[i][j]].r=1;
                A[d[i][j]].r=0;
            }
            P[a[i][j]]=d[i][j];
        }
    }

    for(ll i=0;i<n;i++){
        upd(i,i,0,n-1,1);
    }for(ll i=0;i<n;i++){
        ans+=query(i+1,P[i]-1,0,n-1,1);
        upd(P[i],P[i],0,n-1,1);
    }

    return ans;
}



Compilation message (stderr)

shoes.cpp: In function 'void update(ll, ll, ll, ll, ll)':
shoes.cpp:76:5: error: 'build' was not declared in this scope
   76 |     build(qs,qe,ls);
      |     ^~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:102:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         for(ll j=0;j<a[i].size();j++){
      |                    ~^~~~~~~~~~~~
shoes.cpp:114:9: error: 'upd' was not declared in this scope
  114 |         upd(i,i,0,n-1,1);
      |         ^~~
shoes.cpp:117:9: error: 'upd' was not declared in this scope
  117 |         upd(P[i],P[i],0,n-1,1);
      |         ^~~