답안 #618803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
618803 2022-08-02T07:34:18 Z CSQ31 Team Contest (JOI22_team) C++17
0 / 100
2000 ms 12792 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
typedef pair<int,int> pii;
typedef long long int ll;
const int MAXN = 5e5;
array<ll,3>pts1[MAXN],pts2[MAXN];
vector<int>crd[3];
//i have rectangle queries but i cant do it offline?
//i can but its double log on 2s
//ok try n^2 first
struct seg{
	vector<int>t;
	int n;
	seg(){}
	seg(int _n){
		n = _n;
		t.assign(4*n+1,-2e9);
	}
	void upd(int v,int pos,int l,int r,int val){
		if(l==r){
			t[v] = val;
			return;
		}
		int tm = (l+r)/2;
		if(pos<=tm)upd(2*v,pos,l,tm,val);
		else upd(2*v+1,pos,tm+1,r,val);
		t[v] = max(t[2*v],t[2*v+1]);
	}
	int query(int v,int l,int r,int tl,int tr){
		if(l>r)return -2e9;
		if(l==tl && r==tr)return t[v];
		int tm = (tl+tr)/2;
		if(r<=tm)return query(2*v,l,r,tl,tm);
		else if(l>tm)return query(2*v+1,l,r,tm+1,tr);
		else return max(query(2*v,l,tm,tl,tm),query(2*v+1,tm+1,r,tm+1,tr));
	}
};
int main()
{
	owo
	int n;
	cin>>n;
	vector<array<ll,3>>a(n);
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
			crd[j].pb(a[i][j]);
		}
	}
	sort(all(a),[&](array<ll,3>i,array<ll,3>j){return j[0] > i[0];});
	for(int j=0;j<3;j++){
		sort(all(crd[j]));
		crd[j].resize(unique(all(crd[j])) - crd[j].begin());
	}
	int sz0 = sz(crd[0]);
	int sz1 = sz(crd[1]);
	int sz2 = sz(crd[2]);
	seg bmx(sz1),cmx(sz2);
	for(int i=0;i<n;i++){
		pts1[i][0] = pts2[i][0] = -2e9;
		pts1[i][1] = a[i][1]; //i has bigger b
		pts2[i][2] = a[i][2]; //i has bigger c
		/*
		for(int j=0;j<i;j++){
			if(a[j][1] < a[i][1])pts1[i][2] = max(pts1[i][2],a[j][2]);
			if(a[j][2] < a[i][2])pts2[i][1] = max(pts2[i][1],a[j][1]);
		}*/
		//cout<<a[i][0]<<" "<<a[i][1]<<" "<<a[i][2]<<'\n';
		int s1 = lower_bound(all(crd[1]),a[i][1]) - crd[1].begin();
		int s2 = lower_bound(all(crd[2]),a[i][2]) - crd[2].begin();
		//cout<<s1<<" "<<s2<<'\n';
		if(s1>0)pts1[i][2] = bmx.query(1,0,s1-1,0,sz1-1); //want the max of c among smaller bs
		if(s2>0)pts2[i][1] = cmx.query(1,0,s2-1,0,sz2-1); //want the max of b among smaller cs
		if(pts1[i][2] > a[i][2])pts1[i][0] = pts1[i][1] + pts1[i][2]; 
		if(pts2[i][1] > a[i][1])pts2[i][0] = pts2[i][1] + pts2[i][2];
		
		bmx.upd(1,s1,0,sz1-1,a[i][2]);
		cmx.upd(1,s2,0,sz2-1,a[i][1]);
		
	}
	ll ans = -1;
	for(int i=0;i<n;){
		int k = i;
		while(k+1<n && a[k][0] == a[k+1][0])k++;
		for(int x=i;x<=k;x++){
			for(int j=0;j<x;j++){
				if(a[x][0] == a[j][0])break;
				if(pts1[j][1] > a[x][1] && pts1[j][2] >a[x][2])ans = max(ans,a[x][0] + pts1[j][0]);
				if(pts2[j][1] > a[x][1] && pts2[j][2] >a[x][2])ans = max(ans,a[x][0] + pts2[j][0]);
			}
		}
		i = k+1;
	}
	cout<<ans;
	
	
	
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:61:6: warning: unused variable 'sz0' [-Wunused-variable]
   61 |  int sz0 = sz(crd[0]);
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2062 ms 12792 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2062 ms 12792 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2062 ms 12792 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Execution timed out 2062 ms 12792 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Halted 0 ms 0 KB -