Submission #342495

# Submission time Handle Problem Language Result Execution time Memory
342495 2021-01-02T09:09:03 Z mjhmjh1104 The Potion of Great Power (CEOI20_potion) C++14
18 / 100
731 ms 29184 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;
    auto it1 = upper_bound(s[x].begin(), s[x].end(), pair<int, pair<int, int>>{ v, pair<int, int>{ 1e9, 1e9 } });
    if (it1 == s[x].begin()) return 1e9;
    pair<int, int> first = (it1 - 1)->second;
    auto it2 = upper_bound(s[y].begin(), s[y].end(), pair<int, pair<int, int>>{ v, pair<int, int>{ 1e9, 1e9 } });
    if (it2 == s[y].begin()) return 1e9;
    pair<int, int> second = (it2 - 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:50:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   50 |     if (first.first && second.first || first.second && second.second) return 0;
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~~
potion.cpp:51:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   51 |     else if (first.first && second.second || first.second && second.first) return 1;
      |              ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 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 599 ms 28680 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 731 ms 29184 KB Output is correct
2 Correct 330 ms 12972 KB Output is correct
3 Correct 581 ms 19820 KB Output is correct
4 Correct 571 ms 19692 KB Output is correct
5 Correct 706 ms 28652 KB Output is correct
6 Correct 551 ms 19692 KB Output is correct
# 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 1 ms 364 KB Incorrect