Submission #994901

# Submission time Handle Problem Language Result Execution time Memory
994901 2024-06-08T08:18:41 Z Dzadzo Library (JOI18_library) C++14
100 / 100
390 ms 54820 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;
	int cnt=0;
	for (int x:M)cnt+=x;
	if (cnt==1 || cnt==N)return 1;
	if (MP[M])return MP[M];
	return MP[M]=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:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     if (ind+(1<<bit)>=arr.size())continue;
      |         ~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     if (ind1+(1<<bit)>=arr.size())continue;
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     if (ind2+(1<<bit)>=arr.size())continue;
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~
library.cpp:103:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |    for (int i=0;i<arr.size();i++){
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1868 KB # of queries: 1767
2 Correct 21 ms 1872 KB # of queries: 1772
3 Correct 32 ms 1872 KB # of queries: 1816
4 Correct 24 ms 1836 KB # of queries: 1831
5 Correct 19 ms 1880 KB # of queries: 1783
6 Correct 31 ms 2008 KB # of queries: 1821
7 Correct 19 ms 1916 KB # of queries: 1843
8 Correct 19 ms 1872 KB # of queries: 1730
9 Correct 32 ms 1992 KB # of queries: 1850
10 Correct 12 ms 852 KB # of queries: 1032
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 0
13 Correct 1 ms 344 KB # of queries: 2
14 Correct 0 ms 344 KB # of queries: 5
15 Correct 1 ms 344 KB # of queries: 49
16 Correct 1 ms 344 KB # of queries: 128
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1868 KB # of queries: 1767
2 Correct 21 ms 1872 KB # of queries: 1772
3 Correct 32 ms 1872 KB # of queries: 1816
4 Correct 24 ms 1836 KB # of queries: 1831
5 Correct 19 ms 1880 KB # of queries: 1783
6 Correct 31 ms 2008 KB # of queries: 1821
7 Correct 19 ms 1916 KB # of queries: 1843
8 Correct 19 ms 1872 KB # of queries: 1730
9 Correct 32 ms 1992 KB # of queries: 1850
10 Correct 12 ms 852 KB # of queries: 1032
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 0
13 Correct 1 ms 344 KB # of queries: 2
14 Correct 0 ms 344 KB # of queries: 5
15 Correct 1 ms 344 KB # of queries: 49
16 Correct 1 ms 344 KB # of queries: 128
17 Correct 370 ms 54356 KB # of queries: 13472
18 Correct 390 ms 53508 KB # of queries: 13364
19 Correct 364 ms 54580 KB # of queries: 13472
20 Correct 340 ms 48012 KB # of queries: 12576
21 Correct 307 ms 42976 KB # of queries: 11841
22 Correct 388 ms 54820 KB # of queries: 13524
23 Correct 383 ms 54336 KB # of queries: 13418
24 Correct 113 ms 12856 KB # of queries: 5986
25 Correct 343 ms 52416 KB # of queries: 13216
26 Correct 313 ms 46104 KB # of queries: 12265
27 Correct 123 ms 13140 KB # of queries: 5966
28 Correct 95 ms 8432 KB # of queries: 1996
29 Correct 102 ms 8352 KB # of queries: 1994
30 Correct 103 ms 8272 KB # of queries: 1996