Submission #268611

# Submission time Handle Problem Language Result Execution time Memory
268611 2020-08-16T14:05:49 Z stefantaga Queue (CEOI06_queue) C++14
12 / 100
1000 ms 1568 KB
#include <bits/stdc++.h>

using namespace std;
map <int,int> m;
map <int,pair<int,int> > m1;
int nr,i,n,q;
struct wow
{
    int x,y;
}v[50005];
struct query
{
    int poz;char tip;
}query[50005];
int q1;
pair <int,int> valori[50005];
int pozitie (int x)
{
    int sol=0,i;
    if (m1.find(x)!=m1.end())
    {
        int pozitie=m1[x].first;
        for (i=m1[x].second+1;i<=q1;i++)
        {
            if (valori[i].first<=valori[i].second)
            {
                if (valori[i].first<=m1[x].first+sol&&m1[x].first+sol<=valori[i].second)
            {
                sol++;
            }
            }
            else
            {
                 if (valori[i].first>=m1[x].first+sol&&m1[x].first+sol>=valori[i].second)
            {
                sol--;
            }
            }
        }
        return m1[x].first+sol;
    }
    for (i=1;i<=q1;i++)
        {
            if (valori[i].first<=valori[i].second)
            {
                if (valori[i].first<=x+sol&&x+sol<=valori[i].second)
            {
                sol++;
            }
            }
            else
            {
                if (valori[i].first>=x+sol&&x+sol>=valori[i].second)
            {
                sol--;
            }
            }
        }
    return x+sol;
}
int pozitie1,pozitie2;
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    #ifdef HOME
    ifstream cin("queue.in");
    ofstream cout("queue.out");
    #endif // HOME
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>v[i].x>>v[i].y;
        pozitie1=pozitie(v[i].y);
        pozitie2=pozitie(v[i].x);
        if (pozitie1<=pozitie2)
        {
            valori[++q1]={pozitie1,pozitie2-1};
            m1[v[i].x]={pozitie1,i};
        }
        else
        {
            valori[++q1]={pozitie1-1,pozitie2};
            m1[v[i].x]={pozitie1-1,i};
        }
    }
    cin>>q;
    for (i=1;i<=q;i++)
    {
        cin>>query[i].tip>>query[i].poz;
        if (query[i].tip=='P')
        {
            cout<<pozitie(query[i].poz)<<'\n';
        }
        else
        {
            cout<<"-1"<<'\n';
        }
    }
    return 0;
}

Compilation message

queue.cpp: In function 'int pozitie(int)':
queue.cpp:22:13: warning: unused variable 'pozitie' [-Wunused-variable]
   22 |         int pozitie=m1[x].first;
      |             ^~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 384 KB Partially correct
2 Partially correct 0 ms 384 KB Partially correct
3 Partially correct 7 ms 384 KB Partially correct
4 Partially correct 19 ms 384 KB Partially correct
5 Partially correct 182 ms 1120 KB Partially correct
6 Execution timed out 1057 ms 1272 KB Time limit exceeded
7 Execution timed out 1080 ms 1080 KB Time limit exceeded
8 Execution timed out 1086 ms 1568 KB Time limit exceeded
9 Execution timed out 1088 ms 1312 KB Time limit exceeded
10 Execution timed out 1094 ms 1144 KB Time limit exceeded
11 Execution timed out 1094 ms 1172 KB Time limit exceeded
12 Execution timed out 1085 ms 1272 KB Time limit exceeded
13 Execution timed out 1094 ms 1112 KB Time limit exceeded
14 Execution timed out 1088 ms 1144 KB Time limit exceeded
15 Execution timed out 1079 ms 1272 KB Time limit exceeded
16 Execution timed out 1087 ms 1176 KB Time limit exceeded
17 Partially correct 147 ms 888 KB Partially correct
18 Execution timed out 1083 ms 768 KB Time limit exceeded
19 Execution timed out 1063 ms 896 KB Time limit exceeded
20 Execution timed out 1089 ms 888 KB Time limit exceeded
21 Execution timed out 1080 ms 1272 KB Time limit exceeded
22 Execution timed out 1082 ms 1248 KB Time limit exceeded
23 Execution timed out 1085 ms 1432 KB Time limit exceeded
24 Execution timed out 1086 ms 1272 KB Time limit exceeded
25 Execution timed out 1085 ms 1528 KB Time limit exceeded