답안 #866114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866114 2023-10-25T12:41:18 Z vnm06 The Potion of Great Power (CEOI20_potion) C++14
100 / 100
2294 ms 150140 KB
#include<bits/stdc++.h>
using namespace std;
 
int n, h[1000005];
 
void init(int N, int D, int H[]) 
{
    n=N;
    for(int i=0; i<n; i++) h[i]=H[i];
}
 
map<pair<int, int>, int> globalmp;
 
vector<pair<int, int> > st[2000000];
 
void update(int v, int le, int ri, int be, int en, int st1, int st2)
{
    if(le>en || ri<be) return;
    if(be<=le && ri<=en)
    {
        st[v].push_back({st1, st2});
        st[v].push_back({st2, st1});
        return;
    }
    int mid=(le+ri)/2;
    update(2*v, le, mid, be, en, st1, st2);
    update(2*v+1, mid+1, ri, be, en, st1, st2);
}
 
void curseChanges(int U, int A[], int B[]) 
{
    for(int i=0; i<U; i++)
    {
        if(A[i]>B[i]) swap(A[i], B[i]);
        map<pair<int, int>, int>::iterator it=globalmp.find({A[i], B[i]});
        if(it!=globalmp.end())
        {
            update(1, 0, 2e5+1, (*it).second, i, A[i], B[i]);
            globalmp.erase(it);
        }
        else
        {
            globalmp[{A[i], B[i]}]=i+1;
        }
    }
    map<pair<int, int>, int>::iterator it=globalmp.begin();
    while(it!=globalmp.end())
    {
        update(1, 0, 2e5+1, (*it).second, U, (*it).first.first, (*it).first.second);
        it++;
    }
    for(int i=0; i<2000000; i++) sort(st[i].begin(), st[i].end());
}
 
vector<int> vect[2];
 
void query(int v, int le, int ri, int day, int ch, int id)
{
    while(1)
    {
        int nle=-1, nri=st[v].size();
        while(nri-nle>1)
        {
            int mid=(nle+nri)/2;
            if(st[v][mid].first<ch) nle=mid;
            else nri=mid;
        }
        while(nri<st[v].size() && st[v][nri].first==ch)
        {
            vect[id].push_back(st[v][nri].second);
            nri++;
        }
        if(le==ri) return;
        int mid=(le+ri)/2;
        if(day<=mid)
        {
            v=2*v;
            ri=mid;
        }
        else
        {
            v=2*v+1;
            le=mid+1;

        }
    }
}
 
int question(int x, int y, int v) 
{
    vect[0].resize(0);
    vect[1].resize(0);
    query(1, 0, 2e5+1, v, x, 0);
    query(1, 0, 2e5+1, v, y, 1);
    int s1=vect[0].size(), s2=vect[1].size(), id1=0, id2=0;
    for(int i=0; i<s1; i++) vect[0][i]=h[vect[0][i]];
    for(int i=0; i<s2; i++) vect[1][i]=h[vect[1][i]];
    sort(vect[0].begin(), vect[0].end());
    sort(vect[1].begin(), vect[1].end());
    int tekd=1e9;
    while(id1<s1 && id2<s2)
    {
        int dist=vect[0][id1]-vect[1][id2];
        if(dist<0)
        {
            id1++;
            dist=-dist;
            if(dist<tekd) tekd=dist;
        }
        else
        {
            id2++;
            if(dist<tekd) tekd=dist;
        }
    }
    return tekd;
}

Compilation message

potion.cpp: In function 'void query(int, int, int, int, int, int)':
potion.cpp:68: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]
   68 |         while(nri<st[v].size() && st[v][nri].first==ch)
      |               ~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 47956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 47960 KB Output is correct
2 Correct 16 ms 47960 KB Output is correct
3 Correct 16 ms 47960 KB Output is correct
4 Correct 24 ms 48688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1054 ms 143412 KB Output is correct
2 Correct 1099 ms 150140 KB Output is correct
3 Correct 249 ms 72280 KB Output is correct
4 Correct 1425 ms 114272 KB Output is correct
5 Correct 1156 ms 148344 KB Output is correct
6 Correct 2068 ms 100104 KB Output is correct
7 Correct 727 ms 100300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1231 ms 143796 KB Output is correct
2 Correct 869 ms 77444 KB Output is correct
3 Correct 1144 ms 99988 KB Output is correct
4 Correct 1299 ms 100028 KB Output is correct
5 Correct 1330 ms 142484 KB Output is correct
6 Correct 1375 ms 99836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 51048 KB Output is correct
2 Correct 108 ms 49432 KB Output is correct
3 Correct 111 ms 48920 KB Output is correct
4 Correct 548 ms 50192 KB Output is correct
5 Correct 558 ms 50616 KB Output is correct
6 Correct 140 ms 50820 KB Output is correct
7 Correct 436 ms 49208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 47956 KB Output is correct
2 Correct 16 ms 47960 KB Output is correct
3 Correct 16 ms 47960 KB Output is correct
4 Correct 16 ms 47960 KB Output is correct
5 Correct 24 ms 48688 KB Output is correct
6 Correct 1054 ms 143412 KB Output is correct
7 Correct 1099 ms 150140 KB Output is correct
8 Correct 249 ms 72280 KB Output is correct
9 Correct 1425 ms 114272 KB Output is correct
10 Correct 1156 ms 148344 KB Output is correct
11 Correct 2068 ms 100104 KB Output is correct
12 Correct 727 ms 100300 KB Output is correct
13 Correct 1231 ms 143796 KB Output is correct
14 Correct 869 ms 77444 KB Output is correct
15 Correct 1144 ms 99988 KB Output is correct
16 Correct 1299 ms 100028 KB Output is correct
17 Correct 1330 ms 142484 KB Output is correct
18 Correct 1375 ms 99836 KB Output is correct
19 Correct 103 ms 51048 KB Output is correct
20 Correct 108 ms 49432 KB Output is correct
21 Correct 111 ms 48920 KB Output is correct
22 Correct 548 ms 50192 KB Output is correct
23 Correct 558 ms 50616 KB Output is correct
24 Correct 140 ms 50820 KB Output is correct
25 Correct 436 ms 49208 KB Output is correct
26 Correct 648 ms 73184 KB Output is correct
27 Correct 1478 ms 100116 KB Output is correct
28 Correct 1838 ms 140480 KB Output is correct
29 Correct 1594 ms 114516 KB Output is correct
30 Correct 2294 ms 99916 KB Output is correct
31 Correct 1715 ms 76500 KB Output is correct
32 Correct 2120 ms 100080 KB Output is correct