Submission #859958

# Submission time Handle Problem Language Result Execution time Memory
859958 2023-10-11T08:52:50 Z Tenis0206 The Potion of Great Power (CEOI20_potion) C++11
38 / 100
1422 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 1e5;
const int oo = 1e9;

int n;
int h[nmax + 5];

set<pair<int,int>> s;

vector<int> l;

/*struct Node
{
    Node *st, *dr;
    int val = 0;
    Node()
    {
        st = nullptr;
        dr = nullptr;
        val = 0;
    }
};

struct aint
{
    void update(Node *nod, int val, int nod, int a, int b)
    {
        if(a==b)
        {

        }
    }
    void update_per(int poz, int val, int nr)
    {
        pair<int, *Node> val = {nr, new Node};
        if(r.size())
        {
            val.second -> st = r.back() -> st;
            val.second -> dr = r.back() -> dr;
            val.second -> val = r.back() -> val;
        }
        r.push_back(val);
        update(r.back().second, val, 1,1,n);
    }
};

*/

struct idk
{
    vector<pair<int,set<int>>> r;
    void update_per(int poz, int val, int nr)
    {
        set<int> aux;
        pair<int, set<int> > cur = {nr, aux};
        if(r.size())
        {
            cur.second = r.back().second;
        }
        if(val==0)
        {
            auto it = cur.second.lower_bound(poz);
            cur.second.erase(it);
        }
        else
        {
            cur.second.insert(poz);
        }
        r.push_back(cur);
    }
    void find_friends(int v)
    {
        l.clear();
        int st = 0;
        int dr = r.size() - 1;
        int poz = -1;
        while(st<=dr)
        {
            int mij = (st + dr) >> 1;
            if(r[mij].first <= v)
            {
                poz = mij;
                st = mij + 1;
            }
            else
            {
                dr = mij - 1;
            }
        }
        if(poz==-1)
        {
            return;
        }
        for(auto it=r[poz].second.begin();it!=r[poz].second.end();it++)
        {
            l.push_back(*it);
        }
    }
} ai[nmax + 5];

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

void curseChanges(int U, int A[], int B[])
{
    for(int i=0; i<U; i++)
    {
        int x = A[i];
        int y = B[i];
        if(x > y)
        {
            swap(x,y);
        }
        if(s.find({x,y})==s.end())
        {
            s.insert({x,y});
            ai[x].update_per(y,+1,i + 1);
            ai[y].update_per(x,+1,i + 1);
        }
        else
        {
            auto it = s.find({x,y});
            s.erase(it);
            ai[x].update_per(y,0,i + 1);
            ai[y].update_per(x,0,i + 1);
        }
    }
}

int question(int x, int y, int v)
{
    ai[x].find_friends(v);
    vector<int> vx;
    for(auto it : l)
    {
        vx.push_back(h[it]);
    }
    ai[y].find_friends(v);
    vector<int> vy;
    for(auto it : l)
    {
        vy.push_back(h[it]);
    }
    int Min = oo;
    for(int i=0;i<vx.size();i++)
    {
        for(int j=0;j<vy.size();j++)
        {
            Min = min(Min, abs(vx[i] - vy[j]));
        }
    }
    return Min;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:154:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |     for(int i=0;i<vx.size();i++)
      |                 ~^~~~~~~~~~
potion.cpp:156:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  156 |         for(int j=0;j<vy.size();j++)
      |                     ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 2 ms 3160 KB Output is correct
3 Correct 2 ms 3160 KB Output is correct
4 Correct 10 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 101072 KB Output is correct
2 Correct 577 ms 101356 KB Output is correct
3 Correct 843 ms 206136 KB Output is correct
4 Runtime error 439 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 560 ms 100916 KB Output is correct
2 Runtime error 388 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 6744 KB Output is correct
2 Correct 79 ms 12624 KB Output is correct
3 Correct 112 ms 13272 KB Output is correct
4 Correct 1366 ms 67780 KB Output is correct
5 Correct 1422 ms 51548 KB Output is correct
6 Correct 104 ms 15084 KB Output is correct
7 Correct 940 ms 58180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 3160 KB Output is correct
3 Correct 2 ms 3160 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 10 ms 3664 KB Output is correct
6 Correct 595 ms 101072 KB Output is correct
7 Correct 577 ms 101356 KB Output is correct
8 Correct 843 ms 206136 KB Output is correct
9 Runtime error 439 ms 262144 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -