Submission #1003443

# Submission time Handle Problem Language Result Execution time Memory
1003443 2024-06-20T10:42:42 Z pcc Team Contest (JOI22_team) C++17
100 / 100
459 ms 43564 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define _all(T) T.begin(),T.end()
#define tiii tuple<int,int,int>
#define ai3 array<int,3>

const int mxn = 3e5+10;
const int inf = 1e9+10;

struct BIT{
	int bit[mxn];
	vector<int> v;
	BIT(){}
	void init(){
		fill(bit,bit+mxn,INT_MIN);
		v.clear();
	}
	void reset(){
		for(auto &i:v)bit[i] = INT_MIN;
		v.clear();
	}
	void modify(int p,int val){
		for(;p<mxn;p+=p&-p){
			bit[p] = max(bit[p],val);
			v.push_back(p);
		}
		return;
	}
	int getval(int p){
		int re = INT_MIN;
		for(;p>0;p-= p&-p)re = max(re,bit[p]);
		return re;
	}
};

int ans = INT_MIN;
vector<int> alla,allb,allc;
array<int,3> arr[mxn];
vector<int> v[mxn];
vector<pii> ch[mxn];
int N;
BIT bit;

namespace PREC{
	void GO(){
		bit.init();
		for(int nowa = 1;nowa<alla.size();nowa++){
			for(auto &i:v[nowa]){
				int val = bit.getval(arr[i][1]-1);
				if(val>arr[i][2])ch[nowa].push_back(pii(arr[i][1],val));
				bit.modify(arr[i][1],arr[i][2]);
			}
		}
		bit.init();
		for(int nowa = 1;nowa<alla.size();nowa++){
			for(auto &i:v[nowa]){
				int val = bit.getval(arr[i][2]-1);
				if(val>arr[i][1])ch[nowa].push_back(pii(val,arr[i][2]));
				bit.modify(arr[i][2],arr[i][1]);
			}
		}
		return;
	}
}

namespace CDQ{
	void dc(int l,int r){
		if(l == r)return;
		int mid = (l+r)>>1;
		dc(l,mid);
		dc(mid+1,r);
		bit.reset();
		vector<ai3> vl,vr;//{b,c,val}
		for(int i = l;i<=mid;i++){
			for(auto &j:ch[i]){
				vl.push_back(ai3({j.fs,j.sc,allb[j.fs]+allc[j.sc]}));
			}
		}
		for(int i = mid+1;i<=r;i++){
			for(auto &j:v[i]){
				vr.push_back(ai3({arr[j][1],arr[j][2],alla[arr[j][0]]}));
			}
		}
		sort(vl.begin(),vl.end());
		sort(vr.begin(),vr.end());
		/*
		cerr<<l<<' '<<mid<<' '<<r<<":"<<endl;
		for(auto &i:vl)cerr<<i[0]<<' '<<i[1]<<' '<<i[2]<<',';cerr<<endl;
		for(auto &i:vr)cerr<<i[0]<<' '<<i[1]<<' '<<i[2]<<',';cerr<<endl;

	   */
		while(!vr.empty()||!vl.empty()){
			bool isl = false;
			if(vl.empty())isl = false;
			else if(vr.empty())isl = true;
			else if(vl.back()[0]>vr.back()[0])isl = true;
			else isl = false;
			if(isl){
				auto now = vl.back();vl.pop_back();
				//cerr<<"MODIFY:"<<now[0]<<' '<<now[1]<<' '<<now[2]<<endl;
				bit.modify(mxn-now[1],now[2]);
			}
			else{
				auto now = vr.back();vr.pop_back();
				//cerr<<"GETANS:"<<now[0]<<' '<<now[1]<<' '<<now[2]<<endl;
				int tval = bit.getval(mxn-(now[1]+1))+now[2];
				ans = max(ans,tval);
			}
		}
		return;
	}

	void GO(){
		dc(1,alla.size()-1);
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N;
	alla = allb = allc = {-1};
	for(int i = 1;i<=N;i++){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
		alla.push_back(arr[i][0]);
		allb.push_back(arr[i][1]);
		allc.push_back(arr[i][2]);
	}
	sort(alla.begin(),alla.end());alla.resize(unique(alla.begin(),alla.end())-alla.begin());
	sort(allb.begin(),allb.end());allb.resize(unique(allb.begin(),allb.end())-allb.begin());
	sort(allc.begin(),allc.end());allc.resize(unique(allc.begin(),allc.end())-allc.begin());
	for(int i = 1;i<=N;i++){
		arr[i][0] = lower_bound(_all(alla),arr[i][0])-alla.begin();
		arr[i][1] = lower_bound(_all(allb),arr[i][1])-allb.begin();
		arr[i][2] = lower_bound(_all(allc),arr[i][2])-allc.begin();
		v[arr[i][0]].push_back(i);
	}

	PREC::GO();
	//cerr<<"HI"<<endl;
	CDQ::GO();
/*
	for(int i = 0;i<alla.size();i++)cerr<<alla[i]<<',';cerr<<endl;
	for(int i = 0;i<allb.size();i++)cerr<<allb[i]<<',';cerr<<endl;
	for(int i = 0;i<allc.size();i++)cerr<<allc[i]<<',';cerr<<endl;
	for(int i = 1;i<alla.size();i++){
		cerr<<i<<":"<<endl;
		for(auto &j:ch[i])cerr<<j.fs<<','<<j.sc<<endl;
	}

*/

	cout<<max(ans,-1)<<'\n';
	return 0;
}

Compilation message

team.cpp: In function 'void PREC::GO()':
team.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int nowa = 1;nowa<alla.size();nowa++){
      |                    ~~~~^~~~~~~~~~~~
team.cpp:62:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(int nowa = 1;nowa<alla.size();nowa++){
      |                    ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15704 KB Output is correct
2 Correct 7 ms 15708 KB Output is correct
3 Correct 7 ms 15708 KB Output is correct
4 Correct 7 ms 15708 KB Output is correct
5 Correct 10 ms 15708 KB Output is correct
6 Correct 6 ms 15484 KB Output is correct
7 Correct 6 ms 15656 KB Output is correct
8 Correct 5 ms 15708 KB Output is correct
9 Correct 7 ms 15708 KB Output is correct
10 Correct 8 ms 15708 KB Output is correct
11 Correct 8 ms 15708 KB Output is correct
12 Correct 8 ms 15552 KB Output is correct
13 Correct 7 ms 15704 KB Output is correct
14 Correct 9 ms 15816 KB Output is correct
15 Correct 7 ms 15708 KB Output is correct
16 Correct 7 ms 15708 KB Output is correct
17 Correct 6 ms 15708 KB Output is correct
18 Correct 7 ms 15652 KB Output is correct
19 Correct 7 ms 15764 KB Output is correct
20 Correct 7 ms 15708 KB Output is correct
21 Correct 6 ms 15708 KB Output is correct
22 Correct 6 ms 15708 KB Output is correct
23 Correct 5 ms 15708 KB Output is correct
24 Correct 6 ms 15608 KB Output is correct
25 Correct 7 ms 15708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15704 KB Output is correct
2 Correct 7 ms 15708 KB Output is correct
3 Correct 7 ms 15708 KB Output is correct
4 Correct 7 ms 15708 KB Output is correct
5 Correct 10 ms 15708 KB Output is correct
6 Correct 6 ms 15484 KB Output is correct
7 Correct 6 ms 15656 KB Output is correct
8 Correct 5 ms 15708 KB Output is correct
9 Correct 7 ms 15708 KB Output is correct
10 Correct 8 ms 15708 KB Output is correct
11 Correct 8 ms 15708 KB Output is correct
12 Correct 8 ms 15552 KB Output is correct
13 Correct 7 ms 15704 KB Output is correct
14 Correct 9 ms 15816 KB Output is correct
15 Correct 7 ms 15708 KB Output is correct
16 Correct 7 ms 15708 KB Output is correct
17 Correct 6 ms 15708 KB Output is correct
18 Correct 7 ms 15652 KB Output is correct
19 Correct 7 ms 15764 KB Output is correct
20 Correct 7 ms 15708 KB Output is correct
21 Correct 6 ms 15708 KB Output is correct
22 Correct 6 ms 15708 KB Output is correct
23 Correct 5 ms 15708 KB Output is correct
24 Correct 6 ms 15608 KB Output is correct
25 Correct 7 ms 15708 KB Output is correct
26 Correct 15 ms 16344 KB Output is correct
27 Correct 14 ms 16276 KB Output is correct
28 Correct 11 ms 16384 KB Output is correct
29 Correct 11 ms 16220 KB Output is correct
30 Correct 9 ms 16164 KB Output is correct
31 Correct 12 ms 16340 KB Output is correct
32 Correct 13 ms 16236 KB Output is correct
33 Correct 11 ms 16368 KB Output is correct
34 Correct 12 ms 16304 KB Output is correct
35 Correct 7 ms 15708 KB Output is correct
36 Correct 7 ms 15704 KB Output is correct
37 Correct 9 ms 16200 KB Output is correct
38 Correct 10 ms 16220 KB Output is correct
39 Correct 8 ms 16084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15704 KB Output is correct
2 Correct 6 ms 15708 KB Output is correct
3 Correct 8 ms 15708 KB Output is correct
4 Correct 7 ms 15708 KB Output is correct
5 Correct 6 ms 15708 KB Output is correct
6 Correct 6 ms 15708 KB Output is correct
7 Correct 6 ms 15708 KB Output is correct
8 Correct 8 ms 15708 KB Output is correct
9 Correct 7 ms 15708 KB Output is correct
10 Correct 6 ms 15708 KB Output is correct
11 Correct 90 ms 38320 KB Output is correct
12 Correct 50 ms 28300 KB Output is correct
13 Correct 51 ms 36656 KB Output is correct
14 Correct 76 ms 38324 KB Output is correct
15 Correct 74 ms 38060 KB Output is correct
16 Correct 49 ms 37300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15704 KB Output is correct
2 Correct 6 ms 15708 KB Output is correct
3 Correct 8 ms 15708 KB Output is correct
4 Correct 7 ms 15708 KB Output is correct
5 Correct 6 ms 15708 KB Output is correct
6 Correct 6 ms 15708 KB Output is correct
7 Correct 6 ms 15708 KB Output is correct
8 Correct 8 ms 15708 KB Output is correct
9 Correct 7 ms 15708 KB Output is correct
10 Correct 6 ms 15708 KB Output is correct
11 Correct 90 ms 38320 KB Output is correct
12 Correct 50 ms 28300 KB Output is correct
13 Correct 51 ms 36656 KB Output is correct
14 Correct 76 ms 38324 KB Output is correct
15 Correct 74 ms 38060 KB Output is correct
16 Correct 49 ms 37300 KB Output is correct
17 Correct 6 ms 15704 KB Output is correct
18 Correct 6 ms 15708 KB Output is correct
19 Correct 7 ms 15708 KB Output is correct
20 Correct 6 ms 15708 KB Output is correct
21 Correct 7 ms 15964 KB Output is correct
22 Correct 151 ms 38384 KB Output is correct
23 Correct 151 ms 38064 KB Output is correct
24 Correct 87 ms 29936 KB Output is correct
25 Correct 126 ms 38256 KB Output is correct
26 Correct 79 ms 38312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15704 KB Output is correct
2 Correct 6 ms 15708 KB Output is correct
3 Correct 8 ms 15708 KB Output is correct
4 Correct 7 ms 15708 KB Output is correct
5 Correct 6 ms 15708 KB Output is correct
6 Correct 6 ms 15708 KB Output is correct
7 Correct 6 ms 15708 KB Output is correct
8 Correct 8 ms 15708 KB Output is correct
9 Correct 7 ms 15708 KB Output is correct
10 Correct 6 ms 15708 KB Output is correct
11 Correct 90 ms 38320 KB Output is correct
12 Correct 50 ms 28300 KB Output is correct
13 Correct 51 ms 36656 KB Output is correct
14 Correct 76 ms 38324 KB Output is correct
15 Correct 74 ms 38060 KB Output is correct
16 Correct 49 ms 37300 KB Output is correct
17 Correct 6 ms 15704 KB Output is correct
18 Correct 6 ms 15708 KB Output is correct
19 Correct 7 ms 15708 KB Output is correct
20 Correct 6 ms 15708 KB Output is correct
21 Correct 7 ms 15964 KB Output is correct
22 Correct 151 ms 38384 KB Output is correct
23 Correct 151 ms 38064 KB Output is correct
24 Correct 87 ms 29936 KB Output is correct
25 Correct 126 ms 38256 KB Output is correct
26 Correct 79 ms 38312 KB Output is correct
27 Correct 6 ms 15708 KB Output is correct
28 Correct 6 ms 15616 KB Output is correct
29 Correct 6 ms 15704 KB Output is correct
30 Correct 8 ms 15708 KB Output is correct
31 Correct 11 ms 16220 KB Output is correct
32 Correct 7 ms 15960 KB Output is correct
33 Correct 7 ms 15704 KB Output is correct
34 Correct 232 ms 38900 KB Output is correct
35 Correct 190 ms 35932 KB Output is correct
36 Correct 225 ms 39572 KB Output is correct
37 Correct 199 ms 38716 KB Output is correct
38 Correct 134 ms 39332 KB Output is correct
39 Correct 38 ms 28932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15704 KB Output is correct
2 Correct 6 ms 15708 KB Output is correct
3 Correct 8 ms 15708 KB Output is correct
4 Correct 7 ms 15708 KB Output is correct
5 Correct 6 ms 15708 KB Output is correct
6 Correct 6 ms 15708 KB Output is correct
7 Correct 6 ms 15708 KB Output is correct
8 Correct 8 ms 15708 KB Output is correct
9 Correct 7 ms 15708 KB Output is correct
10 Correct 6 ms 15708 KB Output is correct
11 Correct 90 ms 38320 KB Output is correct
12 Correct 50 ms 28300 KB Output is correct
13 Correct 51 ms 36656 KB Output is correct
14 Correct 76 ms 38324 KB Output is correct
15 Correct 74 ms 38060 KB Output is correct
16 Correct 49 ms 37300 KB Output is correct
17 Correct 6 ms 15704 KB Output is correct
18 Correct 6 ms 15708 KB Output is correct
19 Correct 7 ms 15708 KB Output is correct
20 Correct 6 ms 15708 KB Output is correct
21 Correct 7 ms 15964 KB Output is correct
22 Correct 151 ms 38384 KB Output is correct
23 Correct 151 ms 38064 KB Output is correct
24 Correct 87 ms 29936 KB Output is correct
25 Correct 126 ms 38256 KB Output is correct
26 Correct 79 ms 38312 KB Output is correct
27 Correct 6 ms 15708 KB Output is correct
28 Correct 6 ms 15616 KB Output is correct
29 Correct 6 ms 15704 KB Output is correct
30 Correct 8 ms 15708 KB Output is correct
31 Correct 11 ms 16220 KB Output is correct
32 Correct 7 ms 15960 KB Output is correct
33 Correct 7 ms 15704 KB Output is correct
34 Correct 232 ms 38900 KB Output is correct
35 Correct 190 ms 35932 KB Output is correct
36 Correct 225 ms 39572 KB Output is correct
37 Correct 199 ms 38716 KB Output is correct
38 Correct 134 ms 39332 KB Output is correct
39 Correct 38 ms 28932 KB Output is correct
40 Correct 9 ms 16220 KB Output is correct
41 Correct 11 ms 16344 KB Output is correct
42 Correct 7 ms 16248 KB Output is correct
43 Correct 8 ms 16220 KB Output is correct
44 Correct 307 ms 38760 KB Output is correct
45 Correct 212 ms 34868 KB Output is correct
46 Correct 247 ms 35832 KB Output is correct
47 Correct 210 ms 34428 KB Output is correct
48 Correct 155 ms 40100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15704 KB Output is correct
2 Correct 7 ms 15708 KB Output is correct
3 Correct 7 ms 15708 KB Output is correct
4 Correct 7 ms 15708 KB Output is correct
5 Correct 10 ms 15708 KB Output is correct
6 Correct 6 ms 15484 KB Output is correct
7 Correct 6 ms 15656 KB Output is correct
8 Correct 5 ms 15708 KB Output is correct
9 Correct 7 ms 15708 KB Output is correct
10 Correct 8 ms 15708 KB Output is correct
11 Correct 8 ms 15708 KB Output is correct
12 Correct 8 ms 15552 KB Output is correct
13 Correct 7 ms 15704 KB Output is correct
14 Correct 9 ms 15816 KB Output is correct
15 Correct 7 ms 15708 KB Output is correct
16 Correct 7 ms 15708 KB Output is correct
17 Correct 6 ms 15708 KB Output is correct
18 Correct 7 ms 15652 KB Output is correct
19 Correct 7 ms 15764 KB Output is correct
20 Correct 7 ms 15708 KB Output is correct
21 Correct 6 ms 15708 KB Output is correct
22 Correct 6 ms 15708 KB Output is correct
23 Correct 5 ms 15708 KB Output is correct
24 Correct 6 ms 15608 KB Output is correct
25 Correct 7 ms 15708 KB Output is correct
26 Correct 15 ms 16344 KB Output is correct
27 Correct 14 ms 16276 KB Output is correct
28 Correct 11 ms 16384 KB Output is correct
29 Correct 11 ms 16220 KB Output is correct
30 Correct 9 ms 16164 KB Output is correct
31 Correct 12 ms 16340 KB Output is correct
32 Correct 13 ms 16236 KB Output is correct
33 Correct 11 ms 16368 KB Output is correct
34 Correct 12 ms 16304 KB Output is correct
35 Correct 7 ms 15708 KB Output is correct
36 Correct 7 ms 15704 KB Output is correct
37 Correct 9 ms 16200 KB Output is correct
38 Correct 10 ms 16220 KB Output is correct
39 Correct 8 ms 16084 KB Output is correct
40 Correct 6 ms 15704 KB Output is correct
41 Correct 6 ms 15708 KB Output is correct
42 Correct 8 ms 15708 KB Output is correct
43 Correct 7 ms 15708 KB Output is correct
44 Correct 6 ms 15708 KB Output is correct
45 Correct 6 ms 15708 KB Output is correct
46 Correct 6 ms 15708 KB Output is correct
47 Correct 8 ms 15708 KB Output is correct
48 Correct 7 ms 15708 KB Output is correct
49 Correct 6 ms 15708 KB Output is correct
50 Correct 90 ms 38320 KB Output is correct
51 Correct 50 ms 28300 KB Output is correct
52 Correct 51 ms 36656 KB Output is correct
53 Correct 76 ms 38324 KB Output is correct
54 Correct 74 ms 38060 KB Output is correct
55 Correct 49 ms 37300 KB Output is correct
56 Correct 6 ms 15704 KB Output is correct
57 Correct 6 ms 15708 KB Output is correct
58 Correct 7 ms 15708 KB Output is correct
59 Correct 6 ms 15708 KB Output is correct
60 Correct 7 ms 15964 KB Output is correct
61 Correct 151 ms 38384 KB Output is correct
62 Correct 151 ms 38064 KB Output is correct
63 Correct 87 ms 29936 KB Output is correct
64 Correct 126 ms 38256 KB Output is correct
65 Correct 79 ms 38312 KB Output is correct
66 Correct 6 ms 15708 KB Output is correct
67 Correct 6 ms 15616 KB Output is correct
68 Correct 6 ms 15704 KB Output is correct
69 Correct 8 ms 15708 KB Output is correct
70 Correct 11 ms 16220 KB Output is correct
71 Correct 7 ms 15960 KB Output is correct
72 Correct 7 ms 15704 KB Output is correct
73 Correct 232 ms 38900 KB Output is correct
74 Correct 190 ms 35932 KB Output is correct
75 Correct 225 ms 39572 KB Output is correct
76 Correct 199 ms 38716 KB Output is correct
77 Correct 134 ms 39332 KB Output is correct
78 Correct 38 ms 28932 KB Output is correct
79 Correct 9 ms 16220 KB Output is correct
80 Correct 11 ms 16344 KB Output is correct
81 Correct 7 ms 16248 KB Output is correct
82 Correct 8 ms 16220 KB Output is correct
83 Correct 307 ms 38760 KB Output is correct
84 Correct 212 ms 34868 KB Output is correct
85 Correct 247 ms 35832 KB Output is correct
86 Correct 210 ms 34428 KB Output is correct
87 Correct 155 ms 40100 KB Output is correct
88 Correct 459 ms 43564 KB Output is correct
89 Correct 354 ms 38784 KB Output is correct
90 Correct 425 ms 41380 KB Output is correct
91 Correct 242 ms 35960 KB Output is correct
92 Correct 327 ms 38036 KB Output is correct
93 Correct 293 ms 36844 KB Output is correct
94 Correct 259 ms 34800 KB Output is correct
95 Correct 243 ms 36648 KB Output is correct
96 Correct 202 ms 36432 KB Output is correct
97 Correct 68 ms 40368 KB Output is correct
98 Correct 119 ms 32428 KB Output is correct
99 Correct 133 ms 32592 KB Output is correct