Submission #66190

# Submission time Handle Problem Language Result Execution time Memory
66190 2018-08-10T03:25:41 Z junodeveloper None (KOI18_matrix) C++17
29 / 100
3570 ms 186192 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int m, n, a[4][200010];
vector<int> Ty[4*200010], tree[4*200010];
vector<pair<int, pair<int,int> > > Vq;
void Down(int h, int tl, int tr, int x, int y) {
	if(tr < x || x < tl) return;
	Ty[h].push_back(y);
	if(tl == tr) return;
	int mid = (tl + tr) / 2;
	Down(h*2, tl, mid, x, y); Down(h*2+1, mid+1, tr, x, y);
}
void build(int h, int tl, int tr) {
	sort(all(Ty[h]));
	Ty[h].erase(unique(all(Ty[h])), Ty[h].end());
	tree[h] = vector<int>(4*sz(Ty[h]));
	if(tl == tr) return;
	int mid = (tl + tr) / 2;
	build(h*2, tl, mid); build(h*2+1, mid+1, tr);
}
void update_y(int h1, int h2, int tl, int tr, int y, int v) {
	if(tr < y || y < tl) return;
	if(tl == tr) { tree[h1][h2] = v; return; }
	int mid = (tl + tr) / 2;
	update_y(h1, h2*2, tl, mid, y, v);
	update_y(h1, h2*2+1, mid+1, tr, y, v);
	tree[h1][h2] = max(tree[h1][h2*2], tree[h1][h2*2+1]);
}
void update(int h, int tl, int tr, int x, int y, int v) {
	if(tr < x || x < tl) return;
	update_y(h,1,0,sz(Ty[h])-1,lower_bound(all(Ty[h]),y)-Ty[h].begin(),v);
	if(tl == tr) return;
	int mid = (tl + tr) / 2;
	update(h*2, tl, mid, x,y,v);
	update(h*2+1, mid+1, tr, x,y,v);
}
int query_y(int h1, int h2, int tl, int tr, int l, int r) {
	if(tr < l || r < tl) return 0;
	if(l <= tl && tr <= r) return tree[h1][h2];
	int mid = (tl + tr) / 2;
	return max(query_y(h1,h2*2,tl,mid,l,r), query_y(h1,h2*2+1,mid+1,tr,l,r));
}
int query(int h, int tl, int tr, int x1, int y1, int x2, int y2) {
	if(x1>x2||y1>y2) return 0;
	if(tr < x1 || x2 < tl) return 0;
	if(x1 <= tl && tr <= x2) return
		query_y(h,1,0,sz(Ty[h])-1,lower_bound(all(Ty[h]),y1)-Ty[h].begin(),lower_bound(all(Ty[h]),y2)-Ty[h].begin());
	int mid = (tl + tr) / 2;
	return max(query(h*2, tl, mid, x1,y1,x2,y2),
				query(h*2+1, mid+1, tr, x1,y1,x2,y2));
}
int main() {
	//clock_t start = clock();
	scanf("%d%d", &m, &n);
	for(int i=1; i<=m; i++) {
		vector<int> Vc;
		for(int j=1; j<=n; j++) {
			scanf("%d", &a[i][j]);
			Vc.push_back(a[i][j]);
		}
		sort(all(Vc));
		for(int j=1; j<=n; j++) {
			int c = lower_bound(all(Vc), a[i][j]) - Vc.begin();
			a[i][j] = c;
		}
	}
	for(int i=1; i<=n; i++) {
		int x = a[2][i], y = a[m == 3 ? 3 : 1][i];
		Vq.push_back({a[1][i], {x, y}});
		Down(1,0,n-1,x,y);
	}
	build(1,0,n-1);
	sort(all(Vq));
	int res = 0;
	for(auto& it : Vq) {
		int x=it.second.first,y=it.second.second,q=query(1,0,n-1,0,0,x-1,y-1);
		//printf("x:%d, y:%d, q:%d\n",x,y,q+1);
		update(1,0,n-1,x,y,q+1);
		res = max(res, q+1);
	}
	printf("%d", res);
	//printf("\n%lu", clock() - start);
	return 0;
}

Compilation message

matrix.cpp: In function 'int main()':
matrix.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &m, &n);
  ~~~~~^~~~~~~~~~~~~~~~
matrix.cpp:62:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 116 ms 42208 KB Output is correct
2 Correct 101 ms 42536 KB Output is correct
3 Correct 105 ms 42732 KB Output is correct
4 Correct 90 ms 43048 KB Output is correct
5 Correct 126 ms 43388 KB Output is correct
6 Correct 91 ms 43572 KB Output is correct
7 Correct 99 ms 43936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 44148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 116 ms 42208 KB Output is correct
2 Correct 101 ms 42536 KB Output is correct
3 Correct 105 ms 42732 KB Output is correct
4 Correct 90 ms 43048 KB Output is correct
5 Correct 126 ms 43388 KB Output is correct
6 Correct 91 ms 43572 KB Output is correct
7 Correct 99 ms 43936 KB Output is correct
8 Correct 3373 ms 139880 KB Output is correct
9 Correct 3020 ms 143596 KB Output is correct
10 Correct 1965 ms 147656 KB Output is correct
11 Correct 1998 ms 151384 KB Output is correct
12 Correct 2485 ms 155348 KB Output is correct
13 Correct 2075 ms 159148 KB Output is correct
14 Correct 2360 ms 163084 KB Output is correct
15 Correct 1971 ms 166844 KB Output is correct
16 Correct 2040 ms 170740 KB Output is correct
17 Correct 2004 ms 174752 KB Output is correct
18 Correct 2015 ms 178460 KB Output is correct
19 Correct 2221 ms 182432 KB Output is correct
20 Correct 3570 ms 186192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 44148 KB Output isn't correct
2 Halted 0 ms 0 KB -