Submission #342492

# Submission time Handle Problem Language Result Execution time Memory
342492 2021-01-02T09:02:39 Z mjhmjh1104 The Potion of Great Power (CEOI20_potion) C++14
0 / 100
638 ms 29324 KB
#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

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 time Memory Grader output
1 Incorrect 0 ms 364 KB Incorrect
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 492 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 605 ms 28780 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 638 ms 29324 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2156 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Incorrect