Submission #587828

# Submission time Handle Problem Language Result Execution time Memory
587828 2022-07-02T11:57:40 Z LastRonin Team Contest (JOI22_team) C++14
Compilation error
0 ms 0 KB
#pragma GCC optimize("O3")
 
#include <bits/stdc++.h> 
#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define pill pair<ll, ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
 
const int N = 150002;
const int M = 150002;
const ll hsh[2] = {1555555699, 1222222763};
const ll P = 113;
 
int n;    
int a[N], b[N], c[N];
int sa[N], sb[N], sc[N];
 
 
vector<int> g, g2, g3;

struct node {
	node *l = nullptr, *r = nullptr;
	int val = 0;
} *Brt = new node(), *Crt = new node();
 
struct tdnode {
	tdnode *l = nullptr, *r = nullptr;
	node *val = nullptr;
	tdnode() {
		val = new node();
	}
} *tdrt = new tdnode();
 
vector<ll> scan[M];
 
void upd(int p, int z, node *v, int tl = 0, int tr = M + 1) {
	if(tl == tr) {
		v->val = max(v->val, z);
		return;
	}
	ll m = (tl + tr) >> 1ll;
	if(p <= m) {
		if(!v->l)v->l = new node();
		upd(p, z, v->l, tl, m);
	} else {
		if(!v->r)v->r = new node();
		upd(p, z, v->r, m + 1, tr);
	}
	v->val = max(v->val, z);
}
int get(int l, int r, node *v, int tl = 0, int tr = M + 1) {
	if(l > tr || tl > r || !v) 
		return 0;
	if(l <= tl && tr <= r) 
		return v->val;
	ll m = (tl + tr) >> 1ll;
	return max(get(l, r, v->l, tl, m), get(l, r, v->r, m + 1, tr));
}

struct seg {
    node *t[4 * N];
    void build(int v = 1, int tl = 0, int tr = g2.size()) {
    	if(tl == tr) {
    		t[v] = new node();
    		return;
    	}
    	int m = (tl + tr) >> 1;
    	build(v * 2, tl, m);
    	build(v * 2 + 1, m + 1, tr);
    	t[v] = new node();
    }
	void upd2(int x, int y, int z, int v = 1, int tl = 0, int tr = g2.size()) {
		if(tl == tr) {
			upd(y, z, t[v]);
			return;
		}
		ll m = (tl + tr) >> 1ll;
		if(x <= m) {
			if(!v->l)v->l = new tdnode();
			upd2(x, y, z, t[v]->l, tl, m);
		} else {
			if(!v->r)v->r = new tdnode();
			upd2(x, y, z, t[v]->r, m + 1, tr);
		}
		upd(y, z, t[v]);
	} 
	int get2(int lx, int rx, int ly, int ry, int v, int tl = 0, int  tr = g2.size()) {
		if(lx > tr || rx < tl || !t[v])return 0;
		if(lx <= tl && tr <= rx) {
			return get(ly, ry, t[v]);
		}
		ll m = (tl + tr) >> 1ll;
		return max(get2(lx, rx, ly, ry, t[v]->l, tl , m), get2(lx, rx, ly, ry, t[v]->r, m + 1, tr));
	}
} rot; 
 
bool comp2(int i, int j) {
	return b[i] < b[j];
}
 
bool comp1(int i, int j) {
	return c[i] < c[j];
}
 
int main() {
	speed;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		g.pb(a[i]);
		g2.pb(b[i]);
		g3.pb(c[i]);
	}
	sort(g.begin(), g.end());
	g.erase(unique(g.begin(), g.end()), g.end());
	sort(g2.begin(), g2.end());
	g2.erase(unique(g2.begin(), g2.end()), g2.end());
	sort(g3.begin(), g3.end());
	g3.erase(unique(g3.begin(), g3.end()), g3.end());	
	for(int j = 1; j <= n; j++) {
		sa[j] = lower_bound(g.begin(), g.end(), a[j]) - g.begin() + 1;
		sb[j] = lower_bound(g2.begin(), g2.end(), b[j]) - g2.begin() + 1;
		sc[j] = lower_bound(g3.begin(), g3.end(), c[j]) - g3.begin() + 1;
		scan[sa[j]].pb(j);		
	}
	rot.build();
	int sum = -1;
	for(int i = 1; i <= g.size(); i++) {
		for(auto u : scan[i]) {
			int z = rot.get2(sb[u] + 1, M, sc[u] + 1, M);		
			if(z)sum = max(sum, a[u] + z);
		}
		sort(scan[i].begin(), scan[i].end(), comp1);
		for(auto u : scan[i]) {
			upd(sc[u], sb[u], Crt);	
			int gt2 = get(0, sc[u] - 1, Crt);
			if(gt2 > sb[u]) {
				rot.upd2(gt2, sc[u], c[u] + g2[gt2 - 1]);			
			}
		}
		sort(scan[i].begin(), scan[i].end(), comp2);
		for(auto u : scan[i]) {
			upd(sb[u], sc[u], Brt);
			int gt = get(0, sb[u] - 1, Brt);
			if(gt > sc[u]) {
				rot.upd2(sb[u], gt, b[u] + g3[gt - 1]);			
			}
		}
	}
	cout << sum;
}

Compilation message

team.cpp: In member function 'void seg::upd2(int, int, int, int, int, int)':
team.cpp:83:9: error: base operand of '->' is not a pointer
   83 |    if(!v->l)v->l = new tdnode();
      |         ^~
team.cpp:83:14: error: base operand of '->' is not a pointer
   83 |    if(!v->l)v->l = new tdnode();
      |              ^~
team.cpp:84:24: error: invalid conversion from 'node*' to 'int' [-fpermissive]
   84 |    upd2(x, y, z, t[v]->l, tl, m);
      |                  ~~~~~~^
      |                        |
      |                        node*
team.cpp:76:37: note:   initializing argument 4 of 'void seg::upd2(int, int, int, int, int, int)'
   76 |  void upd2(int x, int y, int z, int v = 1, int tl = 0, int tr = g2.size()) {
      |                                 ~~~~^~~~~
team.cpp:86:9: error: base operand of '->' is not a pointer
   86 |    if(!v->r)v->r = new tdnode();
      |         ^~
team.cpp:86:14: error: base operand of '->' is not a pointer
   86 |    if(!v->r)v->r = new tdnode();
      |              ^~
team.cpp:87:24: error: invalid conversion from 'node*' to 'int' [-fpermissive]
   87 |    upd2(x, y, z, t[v]->r, m + 1, tr);
      |                  ~~~~~~^
      |                        |
      |                        node*
team.cpp:76:37: note:   initializing argument 4 of 'void seg::upd2(int, int, int, int, int, int)'
   76 |  void upd2(int x, int y, int z, int v = 1, int tl = 0, int tr = g2.size()) {
      |                                 ~~~~^~~~~
team.cpp: In member function 'int seg::get2(int, int, int, int, int, int, int)':
team.cpp:97:41: error: invalid conversion from 'node*' to 'int' [-fpermissive]
   97 |   return max(get2(lx, rx, ly, ry, t[v]->l, tl , m), get2(lx, rx, ly, ry, t[v]->r, m + 1, tr));
      |                                   ~~~~~~^
      |                                         |
      |                                         node*
team.cpp:91:47: note:   initializing argument 5 of 'int seg::get2(int, int, int, int, int, int, int)'
   91 |  int get2(int lx, int rx, int ly, int ry, int v, int tl = 0, int  tr = g2.size()) {
      |                                           ~~~~^
team.cpp:97:80: error: invalid conversion from 'node*' to 'int' [-fpermissive]
   97 |   return max(get2(lx, rx, ly, ry, t[v]->l, tl , m), get2(lx, rx, ly, ry, t[v]->r, m + 1, tr));
      |                                                                          ~~~~~~^
      |                                                                                |
      |                                                                                node*
team.cpp:91:47: note:   initializing argument 5 of 'int seg::get2(int, int, int, int, int, int, int)'
   91 |  int get2(int lx, int rx, int ly, int ry, int v, int tl = 0, int  tr = g2.size()) {
      |                                           ~~~~^
team.cpp: In function 'int main()':
team.cpp:132:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |  for(int i = 1; i <= g.size(); i++) {
      |                 ~~^~~~~~~~~~~
team.cpp:134:47: error: no matching function for call to 'seg::get2(int, const int&, int, const int&)'
  134 |    int z = rot.get2(sb[u] + 1, M, sc[u] + 1, M);
      |                                               ^
team.cpp:91:6: note: candidate: 'int seg::get2(int, int, int, int, int, int, int)'
   91 |  int get2(int lx, int rx, int ly, int ry, int v, int tl = 0, int  tr = g2.size()) {
      |      ^~~~
team.cpp:91:6: note:   candidate expects 7 arguments, 4 provided