Submission #943195

# Submission time Handle Problem Language Result Execution time Memory
943195 2024-03-11T09:11:23 Z Lilypad Pilot (NOI19_pilot) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second

const ll N = 1e6+5;

ll n,q,tmp;
long long ans,ansq[N],sz[N];
ll par[N],a[N];
pii b[N],x[N];

ll cost[]

ll root(ll x) {
	if(par[x] == x) return x;
	return par[x] = root(par[x]);
}

void join(ll y, ll z) {
	ll ry = root(y);
	ll rz = root(z);
	if(ry == rz) return;
	par[ry] = rz;
	ans -= (sz[rz] + sz[ry]);
	ans -= (sz[rz]*(sz[rz]-1))/2;
	ans -= (sz[ry]*(sz[ry]-1))/2;
	sz[rz] += sz[ry];
	ans += (sz[rz]*(sz[rz]-1))/2 + sz[rz];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	for(int i=1; i<=n; i++) {
		cin >> a[i];
		b[i].fi = a[i]; b[i].se = i;
		par[i] = i;
	}
	sort(b+1,b+n+1);
	for(int i=1; i<=q; i++) {
		cin >> x[i].fi;
		x[i].se = i;
	}
	sort(x+1,x+q+1);
	ll idx = 1;
	for(int i=1; i<=q; i++) {
		while(idx <= n && b[idx].fi <= x[i].fi) {
			ll var = b[idx].se;
			sz[var] = 1;
			ans++;
			if(var > 1 && sz[var-1] > 0) join(var-1,var);
			if(var < n && sz[var+1] > 0) join(var+1,var);
			idx++;
		}
		ansq[x[i].se] = ans;
	}
	for(int i=1; i<=q; i++) cout << ansq[i] << endl;
}

Compilation message

pilot.cpp:3:12: error: expected initializer before 'int'
    3 | #define ll int
      |            ^~~
pilot.cpp:18:1: note: in expansion of macro 'll'
   18 | ll root(ll x) {
      | ^~
pilot.cpp: In function 'void join(int, int)':
pilot.cpp:24:10: error: 'root' was not declared in this scope
   24 |  ll ry = root(y);
      |          ^~~~