Submission #994847

# Submission time Handle Problem Language Result Execution time Memory
994847 2024-06-08T07:31:04 Z Dzadzo Library (JOI18_library) C++14
100 / 100
352 ms 848 KB
#include <bits/stdc++.h>
#include "library.h"
#define ll long long
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>
#define vi vector <int>
#define vvi vector <vi>
#define vvvi vector <vvi>
#define vp vector <pii>
#define vvp vector <vp>
#define vb vector <bool>
#define vvb vector <vb>;
#define INF INT_MAX
#define MOD 1000000007
#define MAXN 100000
using namespace std;
map <vi,int >MP;
/*int Query(const vi &v){
    if (!MP[v]){
    	for (int x:v)cout<<x;cout<<"\n";
    	cin>>MP[v];
    }
	return MP[v];
}
void Answer(const vi &v){
	cout<<"ANS";
	for (int x:v)cout<<x<<" ";
}*/
vvi arr;
int N;
int get(int l,int r,int idx1,int idx2){
	vi M(N);
	for (int i=l;i<=r;i++){
		for (int x:arr[i])M[x-1]=1;
	}
	if(idx1)M[idx1-1]=1;
	if(idx2)M[idx2-1]=1;
	return Query(M);
}
void Solve(int n){
	N=n;
	arr.pb({1});
	int res=1;
	for (int i=2;i<=n;i++){
//	    cout<<i<<"\n";
		int val=get(0,arr.size()-1,i,0);
		if (val==res+1){
//		    cout<<"AQ1\n";
			arr.pb({i});
			res++;
		}else if (val==res){
//		    cout<<"AQ2\n";
			int ind=-1;
			for (int bit=9;bit>=0;bit--){
				if (ind+(1<<bit)>=arr.size())continue;
				if (get(0,ind+(1<<bit),i,0)>get(0,ind+(1<<bit),0,0))ind+=(1<<bit);
			}
			ind++;//aq aris i
//			cout<<ind<<"---"<<arr[ind][0]<<"\n";
			if (get(0,-1,arr[ind][0],i)==1){
//			    cout<<"MARJVNIV\n";
				arr[ind].insert(arr[ind].begin(),i);
			}else{
//			     cout<<"MARCXNIV\n";
				arr[ind].pb(i);
			}
		}else if (val==res-1){
//		    cout<<"AQ3\n";
			int ind1=-1;
			for (int bit=9;bit>=0;bit--){
				if (ind1+(1<<bit)>=arr.size())continue;
				if (get(0,ind1+(1<<bit),i,0)>get(0,ind1+(1<<bit),0,0))ind1+=(1<<bit);
			}
			ind1++;//aq aris i

			int ind2=-1;
			for (int bit=9;bit>=0;bit--){
				if (ind2+(1<<bit)>=arr.size())continue;
				if (get(0,ind2+(1<<bit),i,0)>=get(0,ind2+(1<<bit),0,0))ind2+=(1<<bit);
			}
			ind2++;// ind1-s aertianebs amastan
			vi newarr;
			if (get(0,-1,arr[ind1][0],i)==1){
//			     cout<<"MARJVNIV\n";
				for (int x:arr[ind2])newarr.pb(x);
				if (get(0,-1,arr[ind2][0],i)==1)reverse(newarr.begin(),newarr.end());
				newarr.pb(i);
				for (int x:arr[ind1])newarr.pb(x);
			}else{
//			     cout<<"MARCXNIV\n";
				for (int x:arr[ind1])newarr.pb(x);
				if (get(0,-1,arr[ind2][0],i)==2)reverse(arr[ind2].begin(),arr[ind2].end());
				newarr.pb(i);
				for (int x:arr[ind2])newarr.pb(x);
			}
			vvi NEWarr;
			for (int i=0;i<arr.size();i++){
				if (i==ind1 || i==ind2)continue;
				NEWarr.pb(arr[i]);
			}
			NEWarr.pb(newarr);
			arr=NEWarr;
			res--;
		}
		
	}
	Answer(arr[0]);
}
/*signed main(){	
	int c;
	cin>>c;
	Solve(c);
}*/

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     if (ind+(1<<bit)>=arr.size())continue;
      |         ~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     if (ind1+(1<<bit)>=arr.size())continue;
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:80:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     if (ind2+(1<<bit)>=arr.size())continue;
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:99:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |    for (int i=0;i<arr.size();i++){
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 29 ms 688 KB # of queries: 2390
2 Correct 27 ms 592 KB # of queries: 2380
3 Correct 21 ms 344 KB # of queries: 2500
4 Correct 16 ms 344 KB # of queries: 2488
5 Correct 27 ms 436 KB # of queries: 2466
6 Correct 20 ms 436 KB # of queries: 2490
7 Correct 17 ms 680 KB # of queries: 2490
8 Correct 22 ms 344 KB # of queries: 2372
9 Correct 33 ms 592 KB # of queries: 2468
10 Correct 16 ms 592 KB # of queries: 1478
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 4
13 Correct 0 ms 344 KB # of queries: 8
14 Correct 0 ms 344 KB # of queries: 16
15 Correct 1 ms 344 KB # of queries: 100
16 Correct 2 ms 344 KB # of queries: 216
# Verdict Execution time Memory Grader output
1 Correct 29 ms 688 KB # of queries: 2390
2 Correct 27 ms 592 KB # of queries: 2380
3 Correct 21 ms 344 KB # of queries: 2500
4 Correct 16 ms 344 KB # of queries: 2488
5 Correct 27 ms 436 KB # of queries: 2466
6 Correct 20 ms 436 KB # of queries: 2490
7 Correct 17 ms 680 KB # of queries: 2490
8 Correct 22 ms 344 KB # of queries: 2372
9 Correct 33 ms 592 KB # of queries: 2468
10 Correct 16 ms 592 KB # of queries: 1478
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 4
13 Correct 0 ms 344 KB # of queries: 8
14 Correct 0 ms 344 KB # of queries: 16
15 Correct 1 ms 344 KB # of queries: 100
16 Correct 2 ms 344 KB # of queries: 216
17 Correct 352 ms 700 KB # of queries: 16624
18 Correct 315 ms 700 KB # of queries: 16492
19 Correct 293 ms 596 KB # of queries: 16636
20 Correct 290 ms 848 KB # of queries: 15572
21 Correct 253 ms 704 KB # of queries: 14708
22 Correct 305 ms 464 KB # of queries: 16916
23 Correct 342 ms 696 KB # of queries: 16744
24 Correct 94 ms 688 KB # of queries: 7584
25 Correct 287 ms 848 KB # of queries: 16266
26 Correct 249 ms 596 KB # of queries: 15242
27 Correct 105 ms 592 KB # of queries: 7688
28 Correct 63 ms 420 KB # of queries: 3996
29 Correct 74 ms 424 KB # of queries: 3992
30 Correct 61 ms 420 KB # of queries: 3996