답안 #642900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
642900 2022-09-20T18:26:01 Z Vladth11 The Potion of Great Power (CEOI20_potion) C++14
38 / 100
3000 ms 116052 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
 
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
 
const int NMAX = 100001;
const int VMAX = 101;
const int INF = 2e9;
const int MOD = 1000000007;
const int BLOCK = 447;
const int base = 117;
const int nr_of_bits = 24;
const int inv2 = 500000004;
 
int catelea[NMAX];
int idx[NMAX];
set <pii> events[NMAX];
vector <int> parcurgere[2];
int ok = 1;
int minim;
int a[NMAX];
int n;
 
struct Node {
    int l, r, cnt;
};
 
int cc = 0;
Node nodes[NMAX * 80];
 
void adauga(int newNode, int node, int l, int r, int val) {
    if(l == r) {
        if(node != -1 && nodes[node].cnt > 0) {
            nodes[newNode].cnt = 0;
        } else {
            nodes[newNode].cnt = 1;
        }
        return;
    }
    int mid = (l + r) / 2;
    int subL = -1, subR = -1;
    if(node != -1) {
        subL = nodes[node].l;
        subR = nodes[node].r;
    }
    if(val <= mid) {
        nodes[newNode].r = subR;
        nodes[cc++] = {-1, -1, 0};
        nodes[newNode].l = cc - 1;
        adauga(nodes[newNode].l, subL, l, mid, val);
    } else {
        nodes[newNode].l = subL;
        nodes[cc++] = {-1, -1, 0};
        nodes[newNode].r = cc - 1;
        adauga(nodes[newNode].r, subR, mid + 1, r, val);
    }
    nodes[newNode].cnt = 0;
    if(nodes[newNode].l != -1){
        nodes[newNode].cnt += nodes[nodes[newNode].l].cnt;
        if(nodes[newNode].l == -1 || nodes[nodes[newNode].l].cnt == 0)
            nodes[newNode].l = -1;
    }
    if(nodes[newNode].r != -1){
        nodes[newNode].cnt += nodes[nodes[newNode].r].cnt;
        if(nodes[nodes[newNode].r].cnt == 0)
            nodes[newNode].r = -1;
    }
}
 
void baga(int node, int l, int r) {
    if(l == r) {
        parcurgere[ok].push_back(a[l]);
        return;
    }
    int mid = (l + r) / 2;
    if(nodes[node].l != -1)
        baga(nodes[node].l, l, mid);
    if(nodes[node].r != -1)
        baga(nodes[node].r, mid + 1, r);
}
 
bool cmp(int aa, int bb) {
    return a[aa] < a[bb];
}
 
void init(int N, int D, int H[]) {
    n = N;
    for(int i = 0; i < N; i++) {
        a[i] = H[i];
        idx[i] = i;
        events[i].insert({0, cc});
        nodes[cc++] = {-1, -1, 0};
    }
    sort(idx, idx + N, cmp);
    for(int i = 0; i < N; i++) {
        catelea[idx[i]] = i;
    }
    for(int i = 0; i < N; i++) {
        a[i] = H[idx[i]];
    }
}
 
void curseChanges(int U, int A[], int B[]) {
    for(int i = 0; i < U; i++) {
        A[i] = catelea[A[i]];
        B[i] = catelea[B[i]];
        int lastA = (*events[A[i]].rbegin()).second;
        int lastB = (*events[B[i]].rbegin()).second;
        events[A[i]].insert({i + 1, cc});
        nodes[cc++] = {-1, -1, 0};
        int index = cc - 1;
        adauga(cc - 1, lastA, 0, n - 1, B[i]);
        events[B[i]].insert({i + 1, cc});
        nodes[cc++] = {-1, -1, 0};
        adauga(cc - 1, lastB, 0, n - 1, A[i]);
    }
}
 
int question(int x, int y, int v) {
    ok = 0;
    x = catelea[x];
    y = catelea[y];
    parcurgere[0].clear();
    parcurgere[1].clear();
    minim = 1e9;
    int lastX = (*prev(events[x].upper_bound({v + 1, 0}))).second;
    int lastY = (*prev(events[y].upper_bound({v + 1, 0}))).second;
    baga(lastX, 0, n - 1);
    if(parcurgere[0].empty())
        return 1e9;
    ok = 1;
    baga(lastY, 0, n - 1);
  	if(parcurgere[1].empty()) return 1e9;
    int i = 0, j = 0;
    while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
        minim = min(minim, abs(parcurgere[0][i] - parcurgere[1][j]));
        if(parcurgere[0][i] > parcurgere[1][j]) {
            j++;
        } else {
            i++;
        }
    }
    return minim;
 
}

Compilation message

potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:115:13: warning: unused variable 'index' [-Wunused-variable]
  115 |         int index = cc - 1;
      |             ^~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:139:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
      |           ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:139:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
      |                                       ~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5456 KB Output is correct
2 Correct 4 ms 5456 KB Output is correct
3 Correct 4 ms 5456 KB Output is correct
4 Correct 40 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 566 ms 115816 KB Output is correct
2 Correct 565 ms 115856 KB Output is correct
3 Correct 471 ms 116052 KB Output is correct
4 Correct 2604 ms 76908 KB Output is correct
5 Correct 1286 ms 93532 KB Output is correct
6 Execution timed out 3080 ms 115800 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 116036 KB Output is correct
2 Execution timed out 3070 ms 115528 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 10064 KB Output is correct
2 Correct 159 ms 10048 KB Output is correct
3 Correct 192 ms 10064 KB Output is correct
4 Correct 1092 ms 10064 KB Output is correct
5 Correct 933 ms 10160 KB Output is correct
6 Correct 172 ms 8656 KB Output is correct
7 Correct 841 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 4 ms 5456 KB Output is correct
3 Correct 4 ms 5456 KB Output is correct
4 Correct 4 ms 5456 KB Output is correct
5 Correct 40 ms 12928 KB Output is correct
6 Correct 566 ms 115816 KB Output is correct
7 Correct 565 ms 115856 KB Output is correct
8 Correct 471 ms 116052 KB Output is correct
9 Correct 2604 ms 76908 KB Output is correct
10 Correct 1286 ms 93532 KB Output is correct
11 Execution timed out 3080 ms 115800 KB Time limit exceeded
12 Halted 0 ms 0 KB -