Submission #928453

# Submission time Handle Problem Language Result Execution time Memory
928453 2024-02-16T12:12:20 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 133524 KB
// Problem: A - Hedgehog Daniyar and Algorithms
// Contest: Virtual Judge - IOI contest #3 (div 1 + 2)
// URL: https://vjudge.net/contest/610287#problem/A
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define S second
#define F first
#define sz size()
#define int long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define yes "YES\n"
#define no "NO\n"
#define ent "\n"
#define give_me_more_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

const int maxn = 1e6 + 5 , mod = 1e9 + 7;

vector <int> g[maxn];

int ans[maxn];
deque <int> dq;
int a[maxn] , t[maxn * 4];

void upd(int v ,int tl , int tr , int pos , int val){
  if(ans[pos] == -1) return;
  if(pos < tl && tr < pos) return;
  if(tl == tr){
    t[v] = val + a[pos];
    return;
  }
  int tm = tl + tr >> 1;
  upd(v * 2 , tl , tm , pos , val);
  upd(v * 2 + 1 ,tm + 1 , tr , pos , val);
  t[v] = max(t[v * 2] , t[v * 2 + 1]);
}

int get(int v , int tl , int tr , int l , int r){
  if(tl > r || l > tr) return 0;
  if(l <= tl && tr <= r) return t[v];
  int tm = tl + tr >> 1;
  return max(get(v * 2, tl , tm , l , r) , get(v * 2 + 1 , tm + 1 ,tr , l , r));
}

void solve(){
  int n , m;
  cin >> n >> m;
  for(int i = 1;i <= n;i++){
    cin >> a[i];
    while(!dq.empty() && dq.back() <= a[i]){
      dq.pop_back();
    }
    if(dq.empty()){
      ans[i] = -1;
    } 
    else ans[i] = dq.back();
    dq.pb(i);
  }
  int res[m + 5];
  int l[m + 5] , r[m + 5] , k[m + 5];
  for(int i = 1;i <= m;i++){
    cin>>l[i] >> r[i] >> k[i];
    g[r[i]].pb(i);
  }
  for(int i = 1;i <= n;i++){
    upd(1 , 1 , n , ans[i] , a[i]);
    for(auto to : g[i]){
      res[to] = get(1 , 1 , n , l[to] , r[to]) > k[to] ? 0 : 1;
    }
  }
  for(int i = 1;i <= m;i++){
    cout<<res[i]<<ent;
  }
}

signed main(){
  give_me_more_speed
  int tt = 1;
  //cin>>t;
  for(int i = 1;i <= tt;i++){
      solve();
  }
}

Compilation message

sortbooks.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:38:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   int tm = tl + tr >> 1;
      |            ~~~^~~~
sortbooks.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:47:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |   int tm = tl + tr >> 1;
      |            ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29532 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Incorrect 7 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29532 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Incorrect 7 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3010 ms 133524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3053 ms 41556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29532 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Incorrect 7 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29532 KB Output is correct
2 Correct 9 ms 29532 KB Output is correct
3 Incorrect 7 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -