답안 #862251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862251 2023-10-17T20:43:57 Z Ahmed_Solyman Volontiranje (COCI21_volontiranje) C++14
50 / 110
1000 ms 100388 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
vector<int>a(100005);
struct segtree{
	vector<ll>tree;
	int size;
	void init(int n){
		size=n;
		tree.assign(n*4+5,0);
	}
	void set(int l,int r,int p,int i,int v){
		if(l>r){
			return;
		}
		if(l==r){
			tree[p]=v;
			return;
		}
		int mid=(l+r)/2;
		if(i>mid){
			set(mid+1,r,p*2+1,i,v);
		}
		else{
			set(l,mid,p*2,i,v);
		}
		tree[p]=max(tree[p*2],tree[p*2+1]);
	}
	void set(int i,int v){
		set(1,size,1,i,v);
	}
	int query(int l,int r,int p,int l_q,int r_q){
		if(l>=l_q && r<=r_q){
			return tree[p];
		}
		if(r<l_q || l>r_q){
			return 0;
		}
		int mid=(l+r)/2;
		return max(query(l,mid,p*2,l_q,r_q),query(mid+1,r,p*2+1,l_q,r_q));
	}
	int query(int l,int r){
		return query(1,size,1,l,r);
	}
};
map<int,bool>vis;
vector<int> LIS(vector<int>p){
	vector<int>arr;
	for(auto i:p){
		if(!vis[i])arr.push_back(i);
	}
	segtree s;
	s.init(p.size());
	int n=arr.size();
	int next[p.size()+1]={},dp[p.size()+1]={};
	vector<set<int>>d(p.size()+1);
	for(int i=n-1;i>=0;i--){
		int mx=s.query(arr[i],p.size());
		if(!mx){
			next[arr[i]]=arr[i];
			dp[arr[i]]=1;
			s.set(arr[i],1);
			d[1].insert(arr[i]);
		}
		else{
			next[arr[i]]=*(d[mx].upper_bound(arr[i]));
			dp[arr[i]]=dp[next[arr[i]]]+1;
			s.set(arr[i],dp[arr[i]]);
			d[dp[arr[i]]].insert(arr[i]);
		}
	}
	int i=*(d[s.query(1,p.size())].begin());
	if(i==0){
		return {};
	}
	vector<int>v;
	v.push_back(i);
	vis[i]=1;
	int cnt=0;
	while(next[i]!=i){
		i=next[i];vis[i]=1;
		v.push_back(i);
	}
	return v;
}
void run(){
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    fast
    //run();
    int n;cin>>n;
    vector<int>arr(n);
    map<int,int>mp;
    int j=1;
    for(auto &i:arr)cin>>i,mp[i]=j++;
    int lis=LIS(arr).size();
	for(auto i:arr)vis[i]=0;
	int cnt=0;
	vector<vector<int>>ans;
	while(1){
		vector<int>v=LIS(arr);
		if(v.size()==lis){
			cnt++;
			ans.push_back(v);
		}
		else{
			break;
		}
	}
	cout<<cnt<<" "<<lis<<endl;
	for(auto i:ans){
		for(auto j:i)cout<<mp[j]<<" ";
		cout<<endl;
	}
    return 0;
}

Compilation message

Main.cpp: In function 'std::vector<int> LIS(std::vector<int>)':
Main.cpp:113:6: warning: unused variable 'cnt' [-Wunused-variable]
  113 |  int cnt=0;
      |      ^~~
Main.cpp: In function 'int main()':
Main.cpp:143:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  143 |   if(v.size()==lis){
      |      ~~~~~~~~^~~~~
Main.cpp: In function 'void run()':
Main.cpp:122:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |     freopen("input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:123:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |     freopen("output.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 760 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 856 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 0 ms 860 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 1012 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 860 KB Output is correct
22 Correct 1 ms 612 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 760 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 856 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 0 ms 860 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 1012 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 860 KB Output is correct
22 Correct 1 ms 612 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 155 ms 1076 KB Output is correct
31 Correct 5 ms 860 KB Output is correct
32 Correct 6 ms 1088 KB Output is correct
33 Correct 52 ms 1124 KB Output is correct
34 Correct 45 ms 1112 KB Output is correct
35 Correct 43 ms 1112 KB Output is correct
36 Correct 2 ms 856 KB Output is correct
37 Correct 2 ms 1056 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 0 ms 860 KB Output is correct
40 Correct 0 ms 604 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 0 ms 860 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 760 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 0 ms 856 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 0 ms 860 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 1012 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 860 KB Output is correct
22 Correct 1 ms 612 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 155 ms 1076 KB Output is correct
31 Correct 5 ms 860 KB Output is correct
32 Correct 6 ms 1088 KB Output is correct
33 Correct 52 ms 1124 KB Output is correct
34 Correct 45 ms 1112 KB Output is correct
35 Correct 43 ms 1112 KB Output is correct
36 Correct 2 ms 856 KB Output is correct
37 Correct 2 ms 1056 KB Output is correct
38 Correct 3 ms 860 KB Output is correct
39 Correct 0 ms 860 KB Output is correct
40 Correct 0 ms 604 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 0 ms 860 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
47 Execution timed out 1022 ms 100388 KB Time limit exceeded
48 Halted 0 ms 0 KB -