답안 #643339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643339 2022-09-21T18:27:46 Z Vladth11 The Potion of Great Power (CEOI20_potion) C++14
0 / 100
249 ms 37584 KB
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>

//#define debug(x) cerr << #x << " " << x << "\n"

#pragma GCC optimize("Ofast")

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int bSize = 40;
const int bits = 15;
const int NMAX = 100000;
const int VMAX = NMAX * 89;

int a[NMAX], n;
int u;
int f[NMAX];
int changer = 0;
int par[NMAX];

struct BLOCK {
    int time;
    vector <int> v;
};

struct cmp {
    bool operator () (int A, int B) {
        return a[A] < a[B];
    }
};

class DS {
public:
    vector <BLOCK> blocks;
    vector <pii> changes;
    set <int, cmp> vecini;
    void baga(int x, int cand) {
        if(vecini.find(x) != vecini.end()) {
            vecini.erase(x);
        } else {
            vecini.insert(x);
        }
        changes.push_back({x, cand});
        if(changes.size() % bSize == 0) {
            BLOCK nou;
            changer++;
            nou.v.clear();
            nou.time = cand;
            for(auto x : vecini) {
                nou.v.push_back(x);
            }
            blocks.push_back(nou);
        }
    }

} ds[NMAX];

void init(int N, int D, int H[]) {
    n = N;
    for(int i = 0; i < N; i++) {
        a[i] = H[i];
    }
}

void curseChanges(int U, int A[], int B[]) {
    u = U;
    for(int i = 0; i < U; i++) {
        int timp = i + 1;
        ds[A[i]].baga(B[i], timp);
        ds[B[i]].baga(A[i], timp);
    }
}

bool cmp(int A, int B) {
    if(a[A] != a[B])
        return a[A] < a[B];
    return A < B;
}

int impX[NMAX];
int impY[NMAX];
int intrebare;
vector <int> parcurgere[2];

int question(int x, int y, int v) {
    int r = -1;
    parcurgere[0].clear();
    parcurgere[1].clear();
    intrebare++;
    if(u != v) {
        int timpX = 0, timpY = 0;
        int pas = (1 << 10), r1 = -1;
        while(pas) {
            if(r + pas < ds[x].blocks.size() && ds[x].blocks[r + pas].time <= v)
                r += pas;
            if(r1 + pas < ds[y].blocks.size() && ds[y].blocks[r1 + pas].time <= v)
                r1 += pas;
            pas /= 2;
        }
        if(r != -1) {
            timpX = ds[x].blocks[r].time + 1;
            parcurgere[0] = ds[x].blocks[r].v;
        }
        if(r1 != -1) {
            timpY = ds[y].blocks[r1].time + 1;
            parcurgere[1] = ds[y].blocks[r1].v;
        }
        r = -1, pas = (1 << bits), r1 = -1;
        while(pas) {
            if(r + pas < ds[x].changes.size() && ds[x].changes[r + pas].second < timpX)
                r += pas;
            if(r1 + pas < ds[y].changes.size() && ds[y].changes[r1 + pas].second < timpY)
                r1 += pas;
            pas /= 2;
        }
        r++;
        for(; r < ds[x].changes.size() && ds[x].changes[r].second <= v; r++) {
            pii change = ds[x].changes[r];
            parcurgere[0].push_back(change.first);
        }
        r1++;
        for(; r1 < ds[y].changes.size() && ds[y].changes[r1].second <= v; r1++) {
            pii change = ds[y].changes[r1];
            parcurgere[1].push_back(change.first);
        }
        if(!parcurgere[0].size() || !parcurgere[1].size()) return 1e9;
        sort(parcurgere[0].begin(), parcurgere[0].end(), cmp);
        sort(parcurgere[1].begin(), parcurgere[1].end(), cmp);

        for(auto x : parcurgere[0]) {
            impX[x] = 0;
        }
        for(auto x : parcurgere[0]) {
            impX[x]++;
        }
        for(auto x : parcurgere[1]) {
            impY[x] = 0;
        }
        for(auto x : parcurgere[1]) {
            impY[x]++;
        }
    } else {
        vector <int> nou(ds[x].vecini.begin(), ds[x].vecini.end());
        parcurgere[0] = nou;
        vector <int> nou2(ds[y].vecini.begin(), ds[y].vecini.end());
        parcurgere[1] = nou2;
    }
    int minim = 1e9;
    int j = 0, i = 0;
    while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
        if(impX[parcurgere[0][i]] % 2 == 0) {
            i++;
            continue;
        }
        if(impY[parcurgere[1][j]] % 2 == 0) {
            j++;
            continue;
        }
        minim = min(minim, abs(a[parcurgere[0][i]] - a[parcurgere[1][j]]));
        if(a[parcurgere[0][i]] < a[parcurgere[1][j]])
            i++;
        else
            j++;
    }
    return minim;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:99:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BLOCK>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |             if(r + pas < ds[x].blocks.size() && ds[x].blocks[r + pas].time <= v)
      |                ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
potion.cpp:101:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<BLOCK>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             if(r1 + pas < ds[y].blocks.size() && ds[y].blocks[r1 + pas].time <= v)
      |                ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
potion.cpp:115:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |             if(r + pas < ds[x].changes.size() && ds[x].changes[r + pas].second < timpX)
      |                ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:117:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |             if(r1 + pas < ds[y].changes.size() && ds[y].changes[r1 + pas].second < timpY)
      |                ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:122:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |         for(; r < ds[x].changes.size() && ds[x].changes[r].second <= v; r++) {
      |               ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:127:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |         for(; r1 < ds[y].changes.size() && ds[y].changes[r1].second <= v; r1++) {
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:155:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
      |           ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:155:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()) {
      |                                       ~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9680 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9808 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 249 ms 37584 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 170 ms 24060 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 11160 KB Output is correct
2 Correct 114 ms 10236 KB Output is correct
3 Incorrect 123 ms 10236 KB Incorrect
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 9680 KB Incorrect
2 Halted 0 ms 0 KB -