Submission #916498

#TimeUsernameProblemLanguageResultExecution timeMemory
916498knatwilaAbracadabra (CEOI22_abracadabra)C++17
10 / 100
794 ms524288 KiB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair	
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define F first
#define S second
#define left(v) (v) + (v)
#define right(v) (v) + (v) + 1
#define ll long long
#define int long long
using namespace std;
///using ll = long long;
//using ull = unsigned long long;
const int MAXN = 1e6 + 5;
const int inf = 4e9;
const long long INF = 1e16;
const int M = 998244353;
const int K = 300;
const int K2 = 600;
const int P = 191;
const int P2 = 191;
const double EPS = 1e-12;
void D_BASE(string name = "") {
	   if (sz(name)) {
	       freopen((name + ".in").c_str(), "r", stdin);
		   freopen((name + ".out").c_str(), "w", stdout);
	   }
	   ios_base::sync_with_stdio(0);
 	   cin.tie(0); 
	   cout.tie(0);
}
//13 20
int n, q;
int a[MAXN];
vector<int> g[MAXN];
void solve() {
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) g[0].pb(a[i]);
	int pos = 0;
	while (true) {
		pos++;
		vector<int> x, y;
		for (int i = 1; i <= n; ++i) {
			if(i <= n / 2) x.pb(a[i]);
			else y.pb(a[i]);
		}
		int posx = 0, posy = 0;
		while (posx < sz(x) && posy < sz(y)) {
			if(x[posx] < y[posy]) {
				g[pos].pb(x[posx]);
				posx++;
			}
			else {
				g[pos].pb(y[posy]);
				posy++;
			}
		}
		while (posx < sz(x)) {
			g[pos].pb(x[posx]);
			posx++;
		}
		while (posy < sz(y)) {
			g[pos].pb(y[posy]);
			posy++;
		}
		bool check = 1;
		for (int i = 1; i <= n; ++i) {
			if(a[i] != g[pos][i - 1]) check = 0;
			a[i] = g[pos][i - 1];
		}
		if(check) break;
	}
	while (q--) {
		int x, y;
		cin >> x >> y;
		int curpos = min(pos, x);
		cout << g[curpos][y - 1] << '\n';
	}
}
signed main() {
    D_BASE("");    
	int tt = 1, ct = 0;
	//cin >> tt;
    while (tt--) {
        //cout << "Case " << ++ct << ":\n";
		solve();
	}
	return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:50:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   while (posx < sz(x) && posy < sz(y)) {
      |               ^
Main.cpp:50:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   while (posx < sz(x) && posy < sz(y)) {
      |                               ^
Main.cpp:60:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   while (posx < sz(x)) {
      |               ^
Main.cpp:64:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   while (posy < sz(y)) {
      |               ^
Main.cpp: In function 'int main()':
Main.cpp:84:14: warning: unused variable 'ct' [-Wunused-variable]
   84 |  int tt = 1, ct = 0;
      |              ^~
Main.cpp: In function 'void D_BASE(std::string)':
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:27:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |      freopen((name + ".out").c_str(), "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...