Submission #1037815

# Submission time Handle Problem Language Result Execution time Memory
1037815 2024-07-29T08:48:07 Z modwwe Abracadabra (CEOI22_abracadabra) C++17
100 / 100
1759 ms 50240 KB
//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
void phongbeo();
const int inf=1e9;
const int mod2=998244353;
const int  mod1=998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c,d,e;

};

int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,l,r,mid;
int  i,s10,s12;
int kk;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
   // fin(task),fou(task);
#endif
    NHP
    /// cin>>s1;
    //  modwwe
    phongbeo();
}
int a[200001];
int ans[1000001];
int c[200001];
int b[200001];
vector<ib> v[200001];
bool d[200001];
struct IT
{
    int t[800001];
    void upd(int node,int l,int r,int l1,int x)
    {
        if(l==r)
        {
            t[node]+=x;
            return;
        }
        int mid=l+r>>1;
        if(l1<=mid)   upd(node<<1,l,mid,l1,x);
        else upd(node<<1|1,mid+1,r,l1,x);
        t[node]=t[node<<1]+t[node<<1|1];
    }
    int get(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1) return 0;
        if(l>=l1&&r<=r1)   return t[node];
        int mid=l+r>>1;
        return get(node<<1,l,mid,l1,r1)+get(node<<1|1,mid+1,r,l1,r1);
    }
    ib bs(int x)
    {
        int l=1;
        int  r=n-1;
        while(l<=r)
        {
            int mid=l+r>>1;
            if(get(1,1,n,1,mid)>=x) r=mid-1;
            else l=mid+1;
        }
        return {x-get(1,1,n,1,r),r+1};
    }
} st;
void go(int x,int y)
{
    while(x<y&&!d[x])
    {
         if(x+b[x]>=y)
        st.upd(1,1,n,a[x],y-x);
        else st.upd(1,1,n,a[x],b[x]);
        d[x]=1;
        x+=b[x];
    }

}
void phongbeo()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>a[i],c[a[i]]=i;
    for(int i=1; i<=m; i++)
    {
        cin>>l>>r;
        if(l>n)l=n;
        if(l==0)ans[i]=a[r];
        else v[l].pb({r,i});
    }
    stack<int> s;
    for(int i=1; i<=n/2; i++)
    {
        while(!s.empty()&&a[s.top()]<a[i])b[s.top()]=i-s.top(),s.pop();
        s.push(i);
    }
    while(!s.empty())b[s.top()]=n/2-s.top()+1,s.pop();
    for(int i=n/2+1; i<=n; i++)
    {
        while(!s.empty()&&a[s.top()]<a[i])b[s.top()]=i-s.top(),s.pop();
        s.push(i);
    }
    while(!s.empty())b[s.top()]=n-s.top()+1,s.pop();
    for(int i=1; i<=n/2; i++)
    {
        if(a[i]>s2) s2=a[i],st.upd(1,1,n,a[i],b[i]),d[i]=1;
    }
    s2=0;
    for(int i=n/2+1; i<=n; i++)
        if(a[i]>s2) s2=a[i],st.upd(1,1,n,a[i],b[i]),d[i]=1;
    s2=0;
    for(int i=1; i<=n; i++)
    {
        if(i>=2)
        {
            ib x=st.bs(n/2);
            s3=x.b;
            s4=st.get(1,1,n,s3,s3);
            s5=s4;
            s4=s4-x.a;
            if(s4!=0)
            {
                st.upd(1,1,n,s3,-s4);
                go(c[s3]+x.a,c[s3]+s5);
            }
        }
        for(auto x:v[i])
        {
            s8=x.b;
            x=st.bs(x.a);
            ans[s8]=a[c[x.b]+x.a-1];
        }
    }
    for(int i=1; i<=m; i++)
       cout<<ans[i],down

    }
/**
10 1
7 5 2 9 10 8 4 3 6 1
2 3
*/

Compilation message

Main.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main()
      | ^~~~
Main.cpp: In member function 'void IT::upd(int, int, int, int, int)':
Main.cpp:77:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   77 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In member function 'int IT::get(int, int, int, int, int)':
Main.cpp:86:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |         int mid=l+r>>1;
      |                 ~^~
Main.cpp: In member function 'ib IT::bs(int)':
Main.cpp:95:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   95 |             int mid=l+r>>1;
      |                     ~^~
# Verdict Execution time Memory Grader output
1 Correct 373 ms 33408 KB Output is correct
2 Correct 393 ms 31888 KB Output is correct
3 Correct 406 ms 31312 KB Output is correct
4 Correct 418 ms 29016 KB Output is correct
5 Correct 447 ms 33104 KB Output is correct
6 Correct 341 ms 33108 KB Output is correct
7 Correct 441 ms 34644 KB Output is correct
8 Correct 363 ms 31564 KB Output is correct
9 Correct 407 ms 30240 KB Output is correct
10 Correct 418 ms 30288 KB Output is correct
11 Correct 383 ms 30800 KB Output is correct
12 Correct 334 ms 27164 KB Output is correct
13 Correct 359 ms 29264 KB Output is correct
14 Correct 379 ms 32532 KB Output is correct
15 Correct 375 ms 29376 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 114 ms 21108 KB Output is correct
18 Correct 238 ms 24768 KB Output is correct
19 Correct 2 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 887 ms 43784 KB Output is correct
2 Correct 826 ms 42620 KB Output is correct
3 Correct 753 ms 35992 KB Output is correct
4 Correct 919 ms 36072 KB Output is correct
5 Correct 988 ms 37048 KB Output is correct
6 Correct 932 ms 37308 KB Output is correct
7 Correct 1103 ms 42264 KB Output is correct
8 Correct 1101 ms 41516 KB Output is correct
9 Correct 1072 ms 36204 KB Output is correct
10 Correct 1080 ms 40472 KB Output is correct
11 Correct 877 ms 35552 KB Output is correct
12 Correct 966 ms 35488 KB Output is correct
13 Correct 1087 ms 39284 KB Output is correct
14 Correct 922 ms 37048 KB Output is correct
15 Correct 1150 ms 41060 KB Output is correct
16 Correct 198 ms 12904 KB Output is correct
17 Correct 287 ms 29804 KB Output is correct
18 Correct 940 ms 31228 KB Output is correct
19 Correct 218 ms 15024 KB Output is correct
20 Correct 377 ms 18888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 14568 KB Output is correct
2 Correct 197 ms 13908 KB Output is correct
3 Correct 213 ms 14164 KB Output is correct
4 Correct 202 ms 13396 KB Output is correct
5 Correct 215 ms 14000 KB Output is correct
6 Correct 176 ms 13396 KB Output is correct
7 Correct 201 ms 13908 KB Output is correct
8 Correct 201 ms 13608 KB Output is correct
9 Correct 211 ms 13820 KB Output is correct
10 Correct 199 ms 13140 KB Output is correct
11 Correct 186 ms 13396 KB Output is correct
12 Correct 209 ms 13328 KB Output is correct
13 Correct 190 ms 13260 KB Output is correct
14 Correct 174 ms 13436 KB Output is correct
15 Correct 229 ms 12928 KB Output is correct
16 Correct 91 ms 10588 KB Output is correct
17 Correct 92 ms 11860 KB Output is correct
18 Correct 126 ms 11464 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 373 ms 33408 KB Output is correct
2 Correct 393 ms 31888 KB Output is correct
3 Correct 406 ms 31312 KB Output is correct
4 Correct 418 ms 29016 KB Output is correct
5 Correct 447 ms 33104 KB Output is correct
6 Correct 341 ms 33108 KB Output is correct
7 Correct 441 ms 34644 KB Output is correct
8 Correct 363 ms 31564 KB Output is correct
9 Correct 407 ms 30240 KB Output is correct
10 Correct 418 ms 30288 KB Output is correct
11 Correct 383 ms 30800 KB Output is correct
12 Correct 334 ms 27164 KB Output is correct
13 Correct 359 ms 29264 KB Output is correct
14 Correct 379 ms 32532 KB Output is correct
15 Correct 375 ms 29376 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 114 ms 21108 KB Output is correct
18 Correct 238 ms 24768 KB Output is correct
19 Correct 2 ms 8536 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 887 ms 43784 KB Output is correct
22 Correct 826 ms 42620 KB Output is correct
23 Correct 753 ms 35992 KB Output is correct
24 Correct 919 ms 36072 KB Output is correct
25 Correct 988 ms 37048 KB Output is correct
26 Correct 932 ms 37308 KB Output is correct
27 Correct 1103 ms 42264 KB Output is correct
28 Correct 1101 ms 41516 KB Output is correct
29 Correct 1072 ms 36204 KB Output is correct
30 Correct 1080 ms 40472 KB Output is correct
31 Correct 877 ms 35552 KB Output is correct
32 Correct 966 ms 35488 KB Output is correct
33 Correct 1087 ms 39284 KB Output is correct
34 Correct 922 ms 37048 KB Output is correct
35 Correct 1150 ms 41060 KB Output is correct
36 Correct 198 ms 12904 KB Output is correct
37 Correct 287 ms 29804 KB Output is correct
38 Correct 940 ms 31228 KB Output is correct
39 Correct 218 ms 15024 KB Output is correct
40 Correct 377 ms 18888 KB Output is correct
41 Correct 192 ms 14568 KB Output is correct
42 Correct 197 ms 13908 KB Output is correct
43 Correct 213 ms 14164 KB Output is correct
44 Correct 202 ms 13396 KB Output is correct
45 Correct 215 ms 14000 KB Output is correct
46 Correct 176 ms 13396 KB Output is correct
47 Correct 201 ms 13908 KB Output is correct
48 Correct 201 ms 13608 KB Output is correct
49 Correct 211 ms 13820 KB Output is correct
50 Correct 199 ms 13140 KB Output is correct
51 Correct 186 ms 13396 KB Output is correct
52 Correct 209 ms 13328 KB Output is correct
53 Correct 190 ms 13260 KB Output is correct
54 Correct 174 ms 13436 KB Output is correct
55 Correct 229 ms 12928 KB Output is correct
56 Correct 91 ms 10588 KB Output is correct
57 Correct 92 ms 11860 KB Output is correct
58 Correct 126 ms 11464 KB Output is correct
59 Correct 2 ms 8540 KB Output is correct
60 Correct 2 ms 8672 KB Output is correct
61 Correct 1549 ms 50240 KB Output is correct
62 Correct 1759 ms 48140 KB Output is correct
63 Correct 1749 ms 47308 KB Output is correct
64 Correct 1510 ms 46520 KB Output is correct
65 Correct 1684 ms 48236 KB Output is correct
66 Correct 1509 ms 46528 KB Output is correct
67 Correct 1520 ms 45768 KB Output is correct
68 Correct 1534 ms 44420 KB Output is correct
69 Correct 1553 ms 46236 KB Output is correct
70 Correct 1343 ms 42868 KB Output is correct
71 Correct 1150 ms 44060 KB Output is correct
72 Correct 1296 ms 43140 KB Output is correct
73 Correct 1230 ms 43348 KB Output is correct
74 Correct 1221 ms 45456 KB Output is correct
75 Correct 1250 ms 44364 KB Output is correct
76 Correct 167 ms 12884 KB Output is correct
77 Correct 323 ms 30036 KB Output is correct
78 Correct 750 ms 32004 KB Output is correct
79 Correct 2 ms 8540 KB Output is correct
80 Correct 2 ms 8540 KB Output is correct