답안 #646951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646951 2022-10-01T08:19:27 Z Vladth11 The Potion of Great Power (CEOI20_potion) C++11
38 / 100
3000 ms 216052 KB
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
 
#pragma pack(1)
#pragma GCC optimize("Ofast,unroll-loops")
 
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
 
const int NMAX = 100000;
const int VMAX = NMAX * 89;
 
int total = 0;
int nxt[NMAX * 100];
int val[NMAX * 100];
 
class lista{
public:
    int cnt = 0;
    int primul = 0;
    int ultimul = 0;
    void init(){
        cnt = primul = ultimul = 0;
    }
    void clear(){
        cnt = 0;
        primul = 0;
        ultimul = 0;
    }
    void push_back(int x){
        if(cnt == 0){
            primul = ultimul = ++total;
        }else{
            nxt[ultimul] = ++total;
            ultimul = total;
        }
        cnt++;
        val[total] = x;
    }
};
 
 
 
int a[NMAX], n;
int u;
int cc = 0;
int l[VMAX];
int r[VMAX];
lista v[VMAX];
bool ok;
int root[NMAX];
vector <int> parcurgere[2];
 
inline void update(int node, int st, int dr, int a, int b, int val){
    if(a <= st && dr <= b){
        v[node].push_back(val);
        return;
    }
    int mid = (st + dr) / 2;
    if(a <= mid){
        if(l[node] == 0){
            l[node] = ++cc;
        }
        update(l[node], st, mid, a, b, val);
    }
    if(b > mid){
        if(r[node] == 0){
            r[node] = ++cc;
        }
        update(r[node], mid + 1, dr, a, b, val);
    }
}
 
inline void query(int node, int st, int dr, int aa){
    if(node == 0)
        return;
    //parcurgere[ok].clear();
    int t = v[node].primul;
    while(t != 0){
        parcurgere[ok].push_back(a[val[t]]);
        t = nxt[t];
    }
    int mid = (st + dr) / 2;
    if(aa <= mid)
        query(l[node], st, mid, aa);
    else
        query(r[node], mid + 1, dr, aa);
}
 
void init(int N, int D, int H[]) {
    n = N;
    for(int i = 0; i < N; i++) {
        a[i] = H[i];
        root[i] = ++cc;
    }
}
 
map <pii, int> mp;
 
void curseChanges(int U, int A[], int B[]) {
    u = U;
    for(int i = 0; i < U; i++){
        if(A[i] > B[i])
            swap(A[i], B[i]);
        pii x = {A[i], B[i]};
        if(mp[x] == 0)
            mp[x] = i + 1;
        else{
            update(root[x.first], 0, U, mp[x], i, x.second);
            update(root[x.second], 0, U, mp[x], i, x.first);
            mp[x] = 0;
        }
    }
    for(auto y : mp){
        pii x = y.first;
        if(mp[x] != 0){
            update(root[x.first], 0, U, mp[x], U, x.second);
            update(root[x.second], 0, U, mp[x], U, x.first);
        }
    }
    mp.clear();
}
 
int question(int x, int y, int v) {
    int minim = 1e9;
    ok = 0;
    parcurgere[ok].clear();
    query(root[x], 0, u, v);
    if(!parcurgere[ok].size()) return minim;
    ok = 1;
    parcurgere[ok].clear();
    query(root[y], 0, u, v);
    if(!parcurgere[ok].size()) return minim;
    sort(parcurgere[0].begin(), parcurgere[0].end());
    sort(parcurgere[1].begin(), parcurgere[1].end());
    //assert(cc <= NMAX * 36);
    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])
            i++;
        else
            j++;
    }
    return minim;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:141:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()){
      |           ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:141:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()){
      |                                       ~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 976 KB Output is correct
2 Correct 2 ms 976 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 15 ms 2888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 631 ms 216052 KB Output is correct
2 Correct 657 ms 215952 KB Output is correct
3 Correct 289 ms 77296 KB Output is correct
4 Correct 2517 ms 134260 KB Output is correct
5 Correct 1317 ms 178724 KB Output is correct
6 Execution timed out 3051 ms 161024 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 636 ms 215956 KB Output is correct
2 Correct 2252 ms 108060 KB Output is correct
3 Correct 1873 ms 166372 KB Output is correct
4 Execution timed out 3051 ms 160900 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 8696 KB Output is correct
2 Correct 79 ms 4688 KB Output is correct
3 Correct 94 ms 3560 KB Output is correct
4 Correct 619 ms 6608 KB Output is correct
5 Correct 580 ms 7632 KB Output is correct
6 Correct 101 ms 6992 KB Output is correct
7 Correct 484 ms 4712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 976 KB Output is correct
3 Correct 2 ms 976 KB Output is correct
4 Correct 2 ms 976 KB Output is correct
5 Correct 15 ms 2888 KB Output is correct
6 Correct 631 ms 216052 KB Output is correct
7 Correct 657 ms 215952 KB Output is correct
8 Correct 289 ms 77296 KB Output is correct
9 Correct 2517 ms 134260 KB Output is correct
10 Correct 1317 ms 178724 KB Output is correct
11 Execution timed out 3051 ms 161024 KB Time limit exceeded
12 Halted 0 ms 0 KB -