Submission #446934

# Submission time Handle Problem Language Result Execution time Memory
446934 2021-07-24T00:51:06 Z jamezzz None (KOI18_matrix) C++17
71 / 100
2448 ms 241812 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define maxn 200005

struct node{
	int s,e,m;
	node *l,*r;
	set<ii> st;
	
	node(int _s,int _e){
		s=_s;e=_e;m=(s+e)/2;st.insert(ii(-1,0));
		if(s!=e)l=new node(s,m),r=new node(m+1,e);
	}
	
	void up(int x,ii pr){
		st.insert(pr);
		auto it=st.find(pr);
		
		if(prev(it)->se>=pr.se){
			st.erase(it);
		}
		else{
			while(next(it)!=st.end()&&next(it)->se<=pr.se){
				st.erase(next(it));
			}
		}
		
		if(s==e)return;
		if(x<=m)l->up(x,pr);
		else r->up(x,pr);
	}
	
	int qry(int x,int y,int v){
		if(s==x&&e==y){
			auto it=st.upper_bound(ii(v,-1));
			return (--it)->se;
		}
		if(y<=m)return l->qry(x,y,v);
		if(x>m)return r->qry(x,y,v);
		return max(l->qry(x,m,v),r->qry(m+1,y,v));
	}
}*root=new node(0,maxn);

int r,n,a[maxn][3],pos[maxn];
vector<int> v;

int main(){
	sf("%d%d",&r,&n);
	for(int i=0;i<n;++i)sf("%d",&a[i][0]);
	for(int i=0;i<n;++i)sf("%d",&a[i][1]);
	for(int i=0;i<n;++i){
		if(r==3)sf("%d",&a[i][2]);
		else a[i][2]=i;
	}
	
	for(int j=0;j<3;++j){
		v.clear();
		for(int i=0;i<n;++i)v.pb(a[i][j]);
		sort(all(v));v.erase(unique(all(v)),v.end());
		for(int i=0;i<n;++i)a[i][j]=lower_bound(all(v),a[i][j])-v.begin()+1;
	}
	for(int i=0;i<n;++i)pos[i]=i;
	sort(pos,pos+n,[&](int i,int j){return a[i][0]<a[j][0];});
	
	for(int i=0;i<n;++i){
		int x=a[pos[i]][1],y=a[pos[i]][2];
		root->up(x,ii(y,root->qry(0,x-1,y)+1));
	}
	
	pf("%d\n",root->qry(0,maxn,INF));
}

Compilation message

matrix.cpp: In function 'int main()':
matrix.cpp:85:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |  sf("%d%d",&r,&n);
      |    ^
matrix.cpp:86:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |  for(int i=0;i<n;++i)sf("%d",&a[i][0]);
      |                        ^
matrix.cpp:87:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |  for(int i=0;i<n;++i)sf("%d",&a[i][1]);
      |                        ^
matrix.cpp:89:13: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |   if(r==3)sf("%d",&a[i][2]);
      |             ^
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 59164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 59816 KB Output is correct
2 Correct 94 ms 60708 KB Output is correct
3 Correct 96 ms 59588 KB Output is correct
4 Correct 97 ms 59104 KB Output is correct
5 Correct 93 ms 59560 KB Output is correct
6 Correct 104 ms 65860 KB Output is correct
7 Correct 98 ms 59524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 59164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 59816 KB Output is correct
2 Correct 94 ms 60708 KB Output is correct
3 Correct 96 ms 59588 KB Output is correct
4 Correct 97 ms 59104 KB Output is correct
5 Correct 93 ms 59560 KB Output is correct
6 Correct 104 ms 65860 KB Output is correct
7 Correct 98 ms 59524 KB Output is correct
8 Correct 1082 ms 115348 KB Output is correct
9 Correct 729 ms 85212 KB Output is correct
10 Correct 1165 ms 138736 KB Output is correct
11 Correct 1376 ms 241812 KB Output is correct
12 Correct 580 ms 85168 KB Output is correct
13 Correct 1098 ms 120132 KB Output is correct
14 Correct 1211 ms 118348 KB Output is correct
15 Correct 1390 ms 228796 KB Output is correct
16 Correct 1397 ms 229056 KB Output is correct
17 Correct 755 ms 85132 KB Output is correct
18 Correct 2448 ms 111056 KB Output is correct
19 Correct 906 ms 85080 KB Output is correct
20 Correct 1113 ms 116252 KB Output is correct
21 Correct 1408 ms 229828 KB Output is correct
22 Correct 2235 ms 118572 KB Output is correct
23 Correct 750 ms 85328 KB Output is correct
24 Correct 925 ms 85120 KB Output is correct
25 Correct 1600 ms 120124 KB Output is correct
26 Correct 882 ms 85172 KB Output is correct
27 Correct 575 ms 85084 KB Output is correct
28 Correct 1378 ms 229896 KB Output is correct
29 Correct 723 ms 85304 KB Output is correct
30 Correct 728 ms 85248 KB Output is correct
31 Correct 922 ms 85188 KB Output is correct
32 Correct 752 ms 85156 KB Output is correct