답안 #865575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865575 2023-10-24T11:03:27 Z mychecksedad Abracadabra (CEOI22_abracadabra) C++17
10 / 100
3000 ms 32876 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;

typedef tree<
array<int, 3>,
null_type,
less<array<int, 3>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int n, q, ans[N];
vector<array<int, 3>> Q;
void solve(){
  cin >> n >> q;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < q; ++i){
    int t, x; cin >> t  >> x;
    Q.pb({t, x - 1, i});
  }
  sort(all(Q));
  bool ok = 1;
  int t = 0;
  int qp = 0;
  while(qp < Q.size() && Q[qp][0] == t){
    ans[Q[qp][2]] = a[Q[qp][1]];
    ++qp;
  }
  ordered_set oset;
  int last = a[0], lastpos = 0;
  for(int i = 0; i < n; ++i){
    if(last < a[i])
      last = a[i], lastpos = i;
    oset.insert({last, i - lastpos, a[i]});
  }
  // for(auto k: oset) cout << k[0] << ' ' << k[1] << ' ' << k[2] << '\n';
    // en;
  while(ok){
    ok = 0;
    int last = 0, lastpos = 0;
    for(int i = n/2; i < n; ++i){
      auto it = oset.find_by_order(i);
      if((*it)[2] > last){
        last = (*it)[2];
        lastpos = i;
      }
      array<int, 3> vv = {last, i - lastpos, (*it)[2]};
      if(last == (*it)[0]) break;
      ok = 1;
      oset.erase(it);
      oset.insert(vv);
    }

    ++t;
    while(qp < Q.size() && (Q[qp][0] == t || !ok)){
      ans[Q[qp][2]] = (*oset.find_by_order(Q[qp][1]))[2];
      ++qp;
    }
    // for(auto k: oset) cout << k[0] << ' ' << k[1] << ' ' << k[2] << '\n';
    // en;
  }

  for(int i = 0; i < q; ++i) cout << ans[i] << '\n';
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:37:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   while(qp < Q.size() && Q[qp][0] == t){
      |         ~~~^~~~~~~~~~
Main.cpp:67:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     while(qp < Q.size() && (Q[qp][0] == t || !ok)){
      |           ~~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:81:15: warning: unused variable 'aa' [-Wunused-variable]
   81 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 24424 KB Output is correct
2 Correct 320 ms 23888 KB Output is correct
3 Correct 330 ms 23228 KB Output is correct
4 Correct 300 ms 22392 KB Output is correct
5 Correct 329 ms 23980 KB Output is correct
6 Correct 300 ms 22704 KB Output is correct
7 Correct 326 ms 24752 KB Output is correct
8 Correct 302 ms 23864 KB Output is correct
9 Correct 295 ms 22320 KB Output is correct
10 Correct 319 ms 23664 KB Output is correct
11 Correct 302 ms 22948 KB Output is correct
12 Correct 288 ms 22308 KB Output is correct
13 Correct 302 ms 22704 KB Output is correct
14 Correct 304 ms 23200 KB Output is correct
15 Correct 316 ms 23456 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 269 ms 22512 KB Output is correct
18 Correct 291 ms 22344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3012 ms 32876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3046 ms 11656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 24424 KB Output is correct
2 Correct 320 ms 23888 KB Output is correct
3 Correct 330 ms 23228 KB Output is correct
4 Correct 300 ms 22392 KB Output is correct
5 Correct 329 ms 23980 KB Output is correct
6 Correct 300 ms 22704 KB Output is correct
7 Correct 326 ms 24752 KB Output is correct
8 Correct 302 ms 23864 KB Output is correct
9 Correct 295 ms 22320 KB Output is correct
10 Correct 319 ms 23664 KB Output is correct
11 Correct 302 ms 22948 KB Output is correct
12 Correct 288 ms 22308 KB Output is correct
13 Correct 302 ms 22704 KB Output is correct
14 Correct 304 ms 23200 KB Output is correct
15 Correct 316 ms 23456 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 269 ms 22512 KB Output is correct
18 Correct 291 ms 22344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Execution timed out 3012 ms 32876 KB Time limit exceeded
22 Halted 0 ms 0 KB -