Submission #967235

# Submission time Handle Problem Language Result Execution time Memory
967235 2024-04-21T14:43:32 Z modwwe Triple Jump (JOI19_jumps) C++17
100 / 100
805 ms 108448 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#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".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int  mod1=998244353;
struct ib
{
    int a;
    int b;
};
struct icd
{
    int a,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,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int  i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
   //   fin(task),fou(task);
//#endif
    NHP
//modwwe
    //  cin>>res;
    ngha(),down
    checktime
}
vector<ib> v[500001];
vector<int>v2[500001];
ic t[2000001];
int t2[2000001];
int a[500001];
int b[500001];
void ff(int x)
{
    for(int i=x*2;i<=x*2+1;i++)
    {
        t[i].a=max(t[x].a,t[i].a);
        if(t[i].a!=0)
        t[i].c=max(t[i].c,t[i].a+t[i].b);
    }
}
void build(int node,int l,int r)
{
     if(l==r){
        t[node].b=a[l]; return;}
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
t[node].b=max(t[node<<1].b,t[node<<1|1].b);
}
void upd(int node,int l,int r,int l1,int r1,int k)
 {//cout<<l<<" "<<r<<" "<<l1<<" "<<r1<<" "<<t[node].c,down
      if(l>r1||r<l1) return;
      if(l>=l1&&r<=r1) {
         t[node].a=max(t[node].a,k);
         t[node].c=max(t[node].c,t[node].a+t[node].b);
         return;
      }
      int mid=l+r>>1;
      ff(node);
      upd(node<<1,l,mid,l1,r1,k);
      upd(node<<1|1,mid+1,r,l1,r1,k);
t[node].c=max(t[node<<1].c,t[node<<1|1].c);
 }
 int get(int node,int l,int r,int r1)
 {
   if(l>r1) return 0;
   if(r<=r1){ return t[node].c;}
   ff(node);
   int mid=l+r>>1;
    return max(get(node<<1,l,mid,r1),get(node<<1|1,mid+1,r,r1));
 }
void ngha()
{
     cin>>n;
      for(int i=1;i<=n;i++)
         cin>>a[i];
         build(1,1,n);
 cin>>m;
  for(int i=1;i<=m;i++)
  {
       cin>>l>>r;
        v[l].pb({r,i});
  } /// chi xet den cai lon hon dau tien :3
   /// va cai lon nhat
   /// neu a<=b<=c thi chon b va c hoac a va b
  stack<int> s;
  for(int i=1;i<=n;i++)
  {
   while(!s.empty()&&a[s.top()]<=a[i])
   {
       v2[s.top()].pb(i);
       s.pop();
   }
   if(!s.empty()) v2[s.top()].pb(i);
  s.push(i);
  }
  for(int i=n-2;i>=1;--i)
  {
      for(auto x:v2[i])
      { ///b-a<=c-b 2b-a<=b
           s2=x*2-i;
           if(s2<=n)
           upd(1,1,n,s2,n,a[i]+a[x]);

         // if(i>=11) cout<<s2<<" "<<a[i]+a[x]<<" "<<t[2].c<<" cucu",down
      }
      for(auto x:v[i])
      {
           b[x.b]=get(1,1,n,x.a);
      }
  }
  for(int i=1;i<=m;i++)
    cout<<b[i],down
}

Compilation message

jumps.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
jumps.cpp: In function 'void build(long long int, long long int, long long int)':
jumps.cpp:75:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 | int mid=l+r>>1;
      |         ~^~
jumps.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
jumps.cpp:88:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   88 |       int mid=l+r>>1;
      |               ~^~
jumps.cpp: In function 'long long int get(long long int, long long int, long long int, long long int)':
jumps.cpp:99:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   99 |    int mid=l+r>>1;
      |            ~^~
jumps.cpp: In function 'void ngha()':
jumps.cpp:105:7: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  105 |       for(int i=1;i<=n;i++)
      |       ^~~
jumps.cpp:107:10: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  107 |          build(1,1,n);
      |          ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28508 KB Output is correct
2 Correct 8 ms 28508 KB Output is correct
3 Correct 8 ms 28508 KB Output is correct
4 Correct 9 ms 28508 KB Output is correct
5 Correct 8 ms 28504 KB Output is correct
6 Correct 8 ms 28508 KB Output is correct
7 Correct 8 ms 28508 KB Output is correct
8 Correct 10 ms 28508 KB Output is correct
9 Correct 9 ms 28500 KB Output is correct
10 Correct 8 ms 28508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28508 KB Output is correct
2 Correct 8 ms 28508 KB Output is correct
3 Correct 8 ms 28508 KB Output is correct
4 Correct 9 ms 28508 KB Output is correct
5 Correct 8 ms 28504 KB Output is correct
6 Correct 8 ms 28508 KB Output is correct
7 Correct 8 ms 28508 KB Output is correct
8 Correct 10 ms 28508 KB Output is correct
9 Correct 9 ms 28500 KB Output is correct
10 Correct 8 ms 28508 KB Output is correct
11 Correct 165 ms 53860 KB Output is correct
12 Correct 158 ms 53844 KB Output is correct
13 Correct 159 ms 54108 KB Output is correct
14 Correct 155 ms 53844 KB Output is correct
15 Correct 156 ms 53876 KB Output is correct
16 Correct 161 ms 53076 KB Output is correct
17 Correct 163 ms 53324 KB Output is correct
18 Correct 160 ms 53072 KB Output is correct
19 Correct 157 ms 53588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 50080 KB Output is correct
2 Correct 70 ms 48864 KB Output is correct
3 Correct 73 ms 50500 KB Output is correct
4 Correct 125 ms 50004 KB Output is correct
5 Correct 125 ms 50076 KB Output is correct
6 Correct 120 ms 49440 KB Output is correct
7 Correct 133 ms 49324 KB Output is correct
8 Correct 119 ms 49236 KB Output is correct
9 Correct 119 ms 49652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28508 KB Output is correct
2 Correct 8 ms 28508 KB Output is correct
3 Correct 8 ms 28508 KB Output is correct
4 Correct 9 ms 28508 KB Output is correct
5 Correct 8 ms 28504 KB Output is correct
6 Correct 8 ms 28508 KB Output is correct
7 Correct 8 ms 28508 KB Output is correct
8 Correct 10 ms 28508 KB Output is correct
9 Correct 9 ms 28500 KB Output is correct
10 Correct 8 ms 28508 KB Output is correct
11 Correct 165 ms 53860 KB Output is correct
12 Correct 158 ms 53844 KB Output is correct
13 Correct 159 ms 54108 KB Output is correct
14 Correct 155 ms 53844 KB Output is correct
15 Correct 156 ms 53876 KB Output is correct
16 Correct 161 ms 53076 KB Output is correct
17 Correct 163 ms 53324 KB Output is correct
18 Correct 160 ms 53072 KB Output is correct
19 Correct 157 ms 53588 KB Output is correct
20 Correct 136 ms 50080 KB Output is correct
21 Correct 70 ms 48864 KB Output is correct
22 Correct 73 ms 50500 KB Output is correct
23 Correct 125 ms 50004 KB Output is correct
24 Correct 125 ms 50076 KB Output is correct
25 Correct 120 ms 49440 KB Output is correct
26 Correct 133 ms 49324 KB Output is correct
27 Correct 119 ms 49236 KB Output is correct
28 Correct 119 ms 49652 KB Output is correct
29 Correct 694 ms 105076 KB Output is correct
30 Correct 548 ms 102012 KB Output is correct
31 Correct 599 ms 105676 KB Output is correct
32 Correct 805 ms 105796 KB Output is correct
33 Correct 718 ms 105764 KB Output is correct
34 Correct 736 ms 103580 KB Output is correct
35 Correct 693 ms 103388 KB Output is correct
36 Correct 752 ms 103148 KB Output is correct
37 Correct 716 ms 104772 KB Output is correct
38 Correct 559 ms 108448 KB Output is correct
39 Correct 502 ms 108408 KB Output is correct
40 Correct 475 ms 104980 KB Output is correct
41 Correct 527 ms 104520 KB Output is correct
42 Correct 480 ms 104584 KB Output is correct
43 Correct 493 ms 105580 KB Output is correct
44 Correct 491 ms 108116 KB Output is correct
45 Correct 500 ms 108152 KB Output is correct
46 Correct 506 ms 104276 KB Output is correct
47 Correct 528 ms 103752 KB Output is correct
48 Correct 500 ms 103780 KB Output is correct
49 Correct 495 ms 106628 KB Output is correct
50 Correct 587 ms 107348 KB Output is correct
51 Correct 608 ms 107404 KB Output is correct
52 Correct 601 ms 104928 KB Output is correct
53 Correct 591 ms 104632 KB Output is correct
54 Correct 559 ms 104596 KB Output is correct
55 Correct 586 ms 106256 KB Output is correct