답안 #512895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
512895 2022-01-16T19:28:17 Z kevinxiehk 커다란 상품 (IOI17_prize) C++17
20 / 100
11 ms 11516 KB
#include "prize.h"
#include "bits/stdc++.h"
using namespace std;
int ddd = 1;
int fen[200005][10];
int corr[10];
int n;
unordered_map<int, int> aaa;
void add(int id, int x, int k) {
    id++;
    while(id <= n) {
        fen[id][k] += x;
        id += (id & (-id));
    }
}
int sum(int id, int k) {
    int ans = 0;
    id++;
    while(id > 0) {
        ans += fen[id][k];
        id -= (id & (-id));
    }
    return ans;
}    
int getbefore(int id, int k) {
    int t = 0;
    for(int i = 1; i < ddd; i++) {
        if(corr[i] < k) t += sum(id, i);
    }
    return t;
}
void add_val(int a, int k) {
    if(aaa[k] == 0) {corr[ddd] = k; aaa[k] = ddd++;}
    add(a, 1, aaa[k]);
}
bool vi[200005];
vector<int> store[200005];
int now = 0;
int dx = 0;
int sign = 1;
vector<int> aa(int t) {
    cerr << t << '\n';
    if(vi[t]) {
        int k = 0;
        while((t - k < 0 ||vi[t - k]) && (t + k >= n || vi[t + k])) k++;
        if(t - k >= 0 && !vi[t - k]) now = t = t - k;
        else now = t = t + k;
    }
    now++;
    assert(now <= 10000);
    // vi[t] = true;
    return store[t] = ask(t);
}
int ans = -1;
int ll = 0, rr = n - 1;
void solve(int l, int r) {
    cerr << l << ' ' << r << '\n';
    if(l > r) return;
    int m = (l + r) / 2;
    vector<int> res = aa(m);
    if(res[0] + res[1] == 0) {ans = m; return;}
    if(!vi[m]) add_val(m, res[0] + res[1]);
    vi[m] = true;
    if(res[1] == 0) rr = m - 1;
    // if(l == r) {
    //     ll = m + 1;
    //     return;
    // }
    if(res[0] == getbefore(m, res[0] + res[1])) {
        ll = m + 1;
        solve(m + 1, r);
    }
    else {
        solve(l, m - 1);
    }
}
int find_best(int N) {
    n = N;
    rr = n - 1;
    // int t = 100;
    while(ans == -1) {
        cerr << "e\n";
        solve(ll, rr);
        // cerr << now << '\n';
        // vector<int> res = aa(now);
		// if(res[0] + res[1] == 0) return now;
        // if(!vi[now]) add_val(now, res[0] + res[1]);
        // vi[now] = true;
        // if(res[0] <= getbefore(now, res[0] + res[1])) {
        //     sign = 1;
        //     dx *= 2;
        //     if(dx == 0) dx++;
        // }
        // else {
        //     sign = -1;
        //     dx /= 2;
        //     if(dx == 0) dx++;
        // }
        
        // if(sign == 1) dx = min(dx, n - 1 - now);
        // else dx = min(dx, now);
        // now += dx * sign;
    }
    return ans;
	// for(int i = 0; i < n; i++) {
	// 	vector<int> res = ask(i);
	// 	if(res[0] + res[1] == 0)
	// 		return i;
	// }
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5056 KB Output is correct
2 Correct 3 ms 5136 KB Output is correct
3 Correct 3 ms 5116 KB Output is correct
4 Correct 3 ms 5132 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5112 KB Output is correct
8 Correct 3 ms 5116 KB Output is correct
9 Correct 3 ms 4936 KB Output is correct
10 Correct 3 ms 5140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5140 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 3 ms 5140 KB Output is correct
5 Correct 3 ms 5104 KB Output is correct
6 Correct 3 ms 5124 KB Output is correct
7 Correct 3 ms 5136 KB Output is correct
8 Correct 3 ms 5136 KB Output is correct
9 Correct 3 ms 4936 KB Output is correct
10 Correct 3 ms 5064 KB Output is correct
11 Runtime error 11 ms 11516 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -