답안 #928467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928467 2024-02-16T12:52:33 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1034 ms 93088 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(pos < tl || tr < pos) return;
  if(tl == tr){
    t[v] = max(val + a[pos], t[v]);
    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++){
    if(ans[i] != -1) 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:37:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |   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:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |   int tm = tl + tr >> 1;
      |            ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 29532 KB Output is correct
2 Correct 7 ms 29532 KB Output is correct
3 Incorrect 6 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 29532 KB Output is correct
2 Correct 7 ms 29532 KB Output is correct
3 Incorrect 6 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1034 ms 93088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 39648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 29532 KB Output is correct
2 Correct 7 ms 29532 KB Output is correct
3 Incorrect 6 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 29532 KB Output is correct
2 Correct 7 ms 29532 KB Output is correct
3 Incorrect 6 ms 29532 KB Output isn't correct
4 Halted 0 ms 0 KB -