답안 #31070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31070 2017-08-06T15:10:22 Z top34051 마상시합 토너먼트 (IOI12_tournament) C++14
0 / 100
13 ms 2576 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 10005
int n;
int sum[maxn], p[maxn], cnt[maxn];
int tree[maxn];
vector<int> temp;
set<int> act;
vector<pair<int,int> > a;

void update(int x,int val) {
    x++;
    while(x<=n) {
        tree[x] += val;
        x += x&-x;
    }
}

int query(int x) {
    x++;
    int res = 0;
    while(x>0) {
        res += tree[x];
        x -= x&-x;
    }
    return res;
}

int findpos(int x) {
    int l,r,mid,res=-1;
    l = 0; r = n-1;
    while(l<=r) {
        mid = (l+r)/2;
        if(query(mid)<=x) res = mid, l = mid+1;
        else r = mid-1;
    }
    return res;
}

int GetBestPosition(int N, int C, int X, int *K, int *L, int *R) {
    int i,j,l,r,ans;
    set<int>::iterator it;
    n = N;
    for(i=0;i<n;i++) sum[i] = sum[i-1] + ((i<n-1 && K[i]>X) ? 1 : 0);
    for(i=0;i<n;i++) update(i,1), act.insert(i);
    for(i=0;i<C;i++) {
        l = findpos(L[i])+1; r = findpos(R[i]+1);
//        printf("%d : [%d, %d]\n",i,l,r);
        temp.clear();
        for(it=act.find(l);it!=act.end() && *it<=r;++it) temp.push_back(*it);
        for(j=0;j<temp.size();j++) update(temp[j],-1), act.erase(temp[j]);
        update(l,1); act.insert(l);
        if(sum[r-1]-sum[l-1]==0) {
//            cnt[l]++, cnt[r+1]--;
            a.push_back({l,r});
        }
    }
    ans = 0;
    for(i=0;i<n;i++) {
        int ok = 0;
        for(int j=0;j<a.size();j++) if(a[j].first<=i && a[j].second>=i) ok++;
        ans = max(ans,ok);
    }
    return ans;
}

Compilation message

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:51:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<temp.size();j++) update(temp[j],-1), act.erase(temp[j]);
                  ^
tournament.cpp:61:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<a.size();j++) if(a[j].first<=i && a[j].second>=i) ok++;
                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Incorrect 0 ms 2180 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 2576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -