답안 #828027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828027 2023-08-17T02:02:53 Z boyliguanhan The Potion of Great Power (CEOI20_potion) C++17
38 / 100
3000 ms 125192 KB
#include<bits/stdc++.h>
//#include "potion.h"
//#pragma GCC optimize(2)
#define NN 100100
#define C 50
using namespace std;
int h[NN], n;
map<int, int> adj[NN];
map<int, set<int>> adj2[NN];
void init(int N, int D, int H[]) {
    n = N;
    for(int i = 0; i < N; i++)
        h[i] = H[i];
}
set<int> arr[100100];
void curseChanges(int U, int A[], int B[]) {
    for(int i = 0; i < n; i++) adj[i][0], adj2[i][0];
    for(int i = 1; i <= U; i++) {
        int a = A[i-1], b = B[i-1];
        set<int> &x = arr[a], &y = arr[b];
        if(x.count(b)) x.erase(b), y.erase(a);
        else x.insert(b), y.insert(a);
        if(!(adj[a].size()%C))
            adj2[a][i] = x;
        if(!(adj[b].size()%C))
            adj2[b][i] = y;
        adj[a][i]=b;
        adj[b][i]=a;
    }
}
int calc(vector<int> a, vector<int> b){
    int ans = 1e9;
    for(int i = 0, j = 0; i < a.size() && j < b.size();i++) {
        if(a[i]>b[j]) swap(a, b), swap(i, j);
        if(j) ans=min(ans,abs(a[i]-b[j-1]));
        ans = min(ans, abs(a[i] - b[j]));
    }
    return ans;
}
int question(int x, int y, int v) {
    set<int> a, b;
    int a2, b2;
    tie(a2,a)=*--adj2[x].upper_bound(v);
    tie(b2,b)=*--adj2[y].upper_bound(v);
    auto it1 = adj[x].upper_bound(a2);
    auto it2 = adj[y].upper_bound(b2);
    while(it1!=adj[x].end()&&it1->first<=v) {
        int X = it1->second;
        if(a.count(X))
            a.erase(X);
        else
            a.insert(X);
        it1++;
    }
    while(it2!=adj[y].end()&&it2->first<=v) {
        int X = it2->second;
        if(b.count(X))
            b.erase(X);
        else
            b.insert(X);
        it2++;
    }
    vector<int> c, d;
    for(auto i: a) c.push_back(h[i]);
    for(auto i: b) d.push_back(h[i]);
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());
    return calc(c,d);
}

Compilation message

potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:33:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i = 0, j = 0; i < a.size() && j < b.size();i++) {
      |                           ~~^~~~~~~~~~
potion.cpp:33:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i = 0, j = 0; i < a.size() && j < b.size();i++) {
      |                                           ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14668 KB Output is correct
2 Correct 10 ms 14672 KB Output is correct
3 Correct 7 ms 14672 KB Output is correct
4 Correct 32 ms 29464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 68436 KB Output is correct
2 Correct 458 ms 68328 KB Output is correct
3 Correct 466 ms 53972 KB Output is correct
4 Correct 2434 ms 91828 KB Output is correct
5 Correct 1293 ms 56600 KB Output is correct
6 Execution timed out 3045 ms 122424 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 68412 KB Output is correct
2 Correct 2533 ms 125192 KB Output is correct
3 Correct 1773 ms 88824 KB Output is correct
4 Correct 2897 ms 122156 KB Output is correct
5 Correct 607 ms 71992 KB Output is correct
6 Execution timed out 3059 ms 122460 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 17788 KB Output is correct
2 Correct 206 ms 16976 KB Output is correct
3 Correct 335 ms 17104 KB Output is correct
4 Correct 1214 ms 18716 KB Output is correct
5 Correct 1254 ms 18672 KB Output is correct
6 Correct 210 ms 16464 KB Output is correct
7 Correct 1008 ms 18136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14416 KB Output is correct
2 Correct 7 ms 14668 KB Output is correct
3 Correct 10 ms 14672 KB Output is correct
4 Correct 7 ms 14672 KB Output is correct
5 Correct 32 ms 29464 KB Output is correct
6 Correct 448 ms 68436 KB Output is correct
7 Correct 458 ms 68328 KB Output is correct
8 Correct 466 ms 53972 KB Output is correct
9 Correct 2434 ms 91828 KB Output is correct
10 Correct 1293 ms 56600 KB Output is correct
11 Execution timed out 3045 ms 122424 KB Time limit exceeded
12 Halted 0 ms 0 KB -