Submission #342492

#TimeUsernameProblemLanguageResultExecution timeMemory
342492mjhmjh1104The Potion of Great Power (CEOI20_potion)C++14
0 / 100
638 ms29324 KiB
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int n, zero[100006], one[100006];
set<pair<int, int>> m;
map<int, vector<pair<int, pair<int, int>>>> s;
vector<int> h;

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

void curseChanges(int U, int A[], int B[]) {
    for (int i = 0; i < U; i++) {
        int a = A[i], b = B[i];
        if (a > b) swap(a, b);
        if (m.count({ a, b })) {
            m.erase({ a, b });
            if (h[a] == 0) zero[b]--;
            else one[b]--;
            if (h[b] == 0) zero[a]--;
            else one[a]--;
            s[a].push_back({ i + 1, { zero[a], one[a] } });
            s[b].push_back({ i + 1, { zero[b], one[b] } });
        } else {
            m.insert({ a, b });
            if (h[a] == 0) zero[b]++;
            else one[b]++;
            if (h[b] == 0) zero[a]++;
            else one[a]++;
            s[a].push_back({ i + 1, { zero[a], one[a] } });
            s[b].push_back({ i + 1, { zero[b], one[b] } });
        }
    }
}

int question(int x, int y, int v) {
    if (s.find(x) == s.end() || s.find(y) == s.end()) return 1e9;
    pair<int, int> first = (upper_bound(s[x].begin(), s[x].end(), pair<int, pair<int, int>>{ v, pair<int, int>{ 1e9, 1e9 } }) - 1)->second;
    pair<int, int> second = (upper_bound(s[y].begin(), s[y].end(), pair<int, pair<int, int>>{ v, pair<int, int>{ 1e9, 1e9 } }) -1)->second;
    if (first.first && second.first || first.second && second.second) return 0;
    else if (first.first && second.second || first.second && second.first) return 1;
    else return 1e9;
}

Compilation message (stderr)

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:46:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   46 |     if (first.first && second.first || first.second && second.second) return 0;
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~~
potion.cpp:47:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   47 |     else if (first.first && second.second || first.second && second.first) return 1;
      |              ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...