제출 #294011

#제출 시각아이디문제언어결과실행 시간메모리
294011humbertoyustaArranging Shoes (IOI19_shoes)C++14
100 / 100
97 ms14528 KiB
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define maxn 200010
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';

int abi[maxn], n, c[maxn], mp[maxn];
long long ans, lans;
vector<int> v[maxn];
pair<pair<int,int>,int> a[maxn];

void update(int id){
    for( ; id > 0; id -= ( id & -id ) )
        abi[id] ++;
}

int query(int id){
    int res = 0;
    for( ; id < maxn; id += ( id & -id ) )
        res += abi[id];
    return res;
}

long long count_swaps(std::vector<int> s) {
	n = (int)s.size();
	int cnt = 0;
	for(int i=0; i<n; i++){
        a[i+1].f.f = 0;
        a[i+1].f.s = i + 1;
        a[i+1].s = s[i];
        if( s[i] < 0 ){
            a[i+1].f.f = ++cnt;
            v[-s[i]].push_back(cnt);
        }
	}
	for(int i=0; i<n; i++){
        if( s[i] > 0 ){
            a[i+1].f.f = v[s[i]][c[s[i]]++];
        }
	}
	cnt = 0;
	for(int i=1; i<=n; i++){
        if( mp[a[i].f.f] ) a[i].f.f = mp[a[i].f.f];
        else{
            mp[a[i].f.f] = ++cnt;
            a[i].f.f = mp[a[i].f.f];
        }
	}

	for(int i=1; i<=n; i++){//db(a[i].f.f)
        ans += query(a[i].f.f+1);
        update(a[i].f.f);
	}
	sort(a+1,a+n+1);
	int c1, c2, l;
	for(int i=1; i<=n; i++){
        if( a[i].f.f != a[i-1].f.f ){
            c1 = 0, c2 = 0, l = i;
        }
        if( a[i].s < 0 ){
            int pos = l + c1 * 2;//db(i)db(pos)
            lans += abs( i - pos );
            c1++;
        }
        if( a[i].s > 0 ){
            int pos = l + 1 + c2 * 2;
            lans += abs( i - pos );//db(i)db(pos)
            c2++;
        }
	}
	//db(ans)
	//db(lans)
	return ans + ( lans ) / 2;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:64:17: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |             int pos = l + c1 * 2;//db(i)db(pos)
      |                 ^~~
shoes.cpp:71:15: warning: 'c2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |             c2++;
      |             ~~^~
shoes.cpp:66:15: warning: 'c1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |             c1++;
      |             ~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...