Submission #875739

# Submission time Handle Problem Language Result Execution time Memory
875739 2023-11-20T12:20:18 Z 8pete8 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
655 ms 65460 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
#include <iomanip>  
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define ll long long    
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,int>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#pragma GCC optimize ("03,unroll-lopps")
const int mxn=1e6+10,inf=1e9;
int n,m;
struct seg{
    int v[2*mxn+10];
    void update(int pos,int val){
        pos+=n;
        v[pos]=max(v[pos],val);
        for(;pos>0;pos>>=1)v[pos>>1]=max(v[pos],v[pos^1]);
    }
    int qry(int l,int r){
        int ans=0;
        for(l+=n,r+=n;l<=r;l>>=1,r>>=1){
            if(l&1)ans=max(ans,v[l++]);
            if(!(r&1))ans=max(ans,v[r--]);
        }
        return ans;
    }
}t;
int32_t main(){
    fastio
    cin>>n>>m;
    vector<int>v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    vector<ppii>g;
    vector<pair<pii,pii>>q(m);
    for(int i=0;i<m;i++)cin>>q[i].f.f>>q[i].f.s>>q[i].s.f,q[i].s.s=i,q[i].f.f--,q[i].f.s--;
    stack<int>st;
    for(int i=0;i<n;i++){
        while(!st.empty()&&v[st.top()]<=v[i])st.pop();
        if(!st.empty())g.pb({{st.top(),i},v[i]+v[st.top()]});
        st.push(i);
    }
    sort(rall(g));
    sort(rall(q));
    vector<int>ans(m,0);
    int cur=0;
    for(int i=0;i<m;i++){
        while(cur<g.size()&&g[cur].f.f>=q[i].f.f)t.update(g[cur].f.s,g[cur].s),cur++;
        ans[q[i].s.s]=(t.qry(0,q[i].f.s)<=q[i].s.f);
    }
    for(auto i:ans)cout<<i<<'\n';
}

Compilation message

sortbooks.cpp:35:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   35 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
sortbooks.cpp:40:32: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   40 |     void update(int pos,int val){
      |                                ^
sortbooks.cpp:45:24: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   45 |     int qry(int l,int r){
      |                        ^
sortbooks.cpp:54:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   54 | int32_t main(){
      |              ^
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         while(cur<g.size()&&g[cur].f.f>=q[i].f.f)t.update(g[cur].f.s,g[cur].s),cur++;
      |               ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 808 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 655 ms 45536 KB Output is correct
2 Correct 639 ms 45472 KB Output is correct
3 Correct 581 ms 45596 KB Output is correct
4 Correct 613 ms 45292 KB Output is correct
5 Correct 504 ms 25916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 4748 KB Output is correct
2 Correct 51 ms 4748 KB Output is correct
3 Correct 60 ms 2900 KB Output is correct
4 Correct 42 ms 2936 KB Output is correct
5 Correct 42 ms 2888 KB Output is correct
6 Correct 41 ms 3352 KB Output is correct
7 Correct 40 ms 3348 KB Output is correct
8 Correct 69 ms 4300 KB Output is correct
9 Correct 37 ms 2396 KB Output is correct
10 Correct 53 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 808 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 114 ms 9364 KB Output is correct
20 Correct 156 ms 9348 KB Output is correct
21 Correct 117 ms 9568 KB Output is correct
22 Correct 130 ms 9440 KB Output is correct
23 Correct 128 ms 9352 KB Output is correct
24 Correct 94 ms 5456 KB Output is correct
25 Correct 107 ms 5460 KB Output is correct
26 Correct 97 ms 5408 KB Output is correct
27 Correct 110 ms 5456 KB Output is correct
28 Correct 114 ms 5392 KB Output is correct
29 Correct 97 ms 5456 KB Output is correct
30 Correct 100 ms 5456 KB Output is correct
31 Correct 109 ms 5416 KB Output is correct
32 Correct 99 ms 5396 KB Output is correct
33 Correct 109 ms 5460 KB Output is correct
34 Correct 106 ms 5404 KB Output is correct
35 Correct 93 ms 5400 KB Output is correct
36 Correct 94 ms 5392 KB Output is correct
37 Correct 106 ms 5516 KB Output is correct
38 Correct 97 ms 5396 KB Output is correct
39 Correct 110 ms 6856 KB Output is correct
40 Correct 80 ms 5968 KB Output is correct
41 Correct 94 ms 7896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 808 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 3 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 655 ms 45536 KB Output is correct
20 Correct 639 ms 45472 KB Output is correct
21 Correct 581 ms 45596 KB Output is correct
22 Correct 613 ms 45292 KB Output is correct
23 Correct 504 ms 25916 KB Output is correct
24 Correct 63 ms 4748 KB Output is correct
25 Correct 51 ms 4748 KB Output is correct
26 Correct 60 ms 2900 KB Output is correct
27 Correct 42 ms 2936 KB Output is correct
28 Correct 42 ms 2888 KB Output is correct
29 Correct 41 ms 3352 KB Output is correct
30 Correct 40 ms 3348 KB Output is correct
31 Correct 69 ms 4300 KB Output is correct
32 Correct 37 ms 2396 KB Output is correct
33 Correct 53 ms 4044 KB Output is correct
34 Correct 114 ms 9364 KB Output is correct
35 Correct 156 ms 9348 KB Output is correct
36 Correct 117 ms 9568 KB Output is correct
37 Correct 130 ms 9440 KB Output is correct
38 Correct 128 ms 9352 KB Output is correct
39 Correct 94 ms 5456 KB Output is correct
40 Correct 107 ms 5460 KB Output is correct
41 Correct 97 ms 5408 KB Output is correct
42 Correct 110 ms 5456 KB Output is correct
43 Correct 114 ms 5392 KB Output is correct
44 Correct 97 ms 5456 KB Output is correct
45 Correct 100 ms 5456 KB Output is correct
46 Correct 109 ms 5416 KB Output is correct
47 Correct 99 ms 5396 KB Output is correct
48 Correct 109 ms 5460 KB Output is correct
49 Correct 106 ms 5404 KB Output is correct
50 Correct 93 ms 5400 KB Output is correct
51 Correct 94 ms 5392 KB Output is correct
52 Correct 106 ms 5516 KB Output is correct
53 Correct 97 ms 5396 KB Output is correct
54 Correct 110 ms 6856 KB Output is correct
55 Correct 80 ms 5968 KB Output is correct
56 Correct 94 ms 7896 KB Output is correct
57 Correct 627 ms 45472 KB Output is correct
58 Correct 645 ms 45748 KB Output is correct
59 Correct 602 ms 45388 KB Output is correct
60 Correct 625 ms 45804 KB Output is correct
61 Correct 618 ms 45440 KB Output is correct
62 Correct 626 ms 62380 KB Output is correct
63 Correct 512 ms 42124 KB Output is correct
64 Correct 495 ms 41984 KB Output is correct
65 Correct 559 ms 42652 KB Output is correct
66 Correct 528 ms 42620 KB Output is correct
67 Correct 540 ms 26172 KB Output is correct
68 Correct 523 ms 25928 KB Output is correct
69 Correct 517 ms 26120 KB Output is correct
70 Correct 519 ms 25936 KB Output is correct
71 Correct 520 ms 25868 KB Output is correct
72 Correct 496 ms 25908 KB Output is correct
73 Correct 520 ms 53320 KB Output is correct
74 Correct 480 ms 60932 KB Output is correct
75 Correct 507 ms 59924 KB Output is correct
76 Correct 501 ms 60072 KB Output is correct
77 Correct 533 ms 60028 KB Output is correct
78 Correct 549 ms 61628 KB Output is correct
79 Correct 414 ms 49352 KB Output is correct
80 Correct 516 ms 65460 KB Output is correct