Submission #101041

#TimeUsernameProblemLanguageResultExecution timeMemory
101041ecasdqinaConstruction of Highway (JOI18_construction)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

struct SegmentTree {
	std::vector<i64> seg, lazy;
	int sz = 1;
	
	SegmentTree(int n) {
		while(sz < n) sz <<= 1;
		seg.assign(sz * 2 - 1, 0);
	}
	void add(int k, int x = 1) {
		k += sz - 1;
		seg[k] += x;
		
		while(k) {
			k = (k - 1) >> 1;
			
			seg[k] = seg[2 * k + 1] + seg[2 * k + 2];
		}
	}
	void update(int k, int x = 1) {
		k += sz - 1;
		seg[k] = x;
		
		while(k) {
			k = (k - 1) >> 1;
			
			seg[k] = seg[2 * k + 1] + seg[2 * k + 2];
		}
	}
	void add(
	i64 get(int a, int b, int k, int l, int r) {
		if(b <= l || r <= a) return 0;
		if(a <= l && r <= b) return seg[k];
		
		i64 L = get(a, b, 2 * k + 1, l, (l + r) >> 1);
		i64 R = get(a, b, 2 * k + 2, (l + r) >> 1, r);
		return L + R;
	}
	i64 get(int a, int b) {
		return get(a, b, 0, 0, sz);
	}
	i64 operator[](int k) {
		return seg[k + sz - 1];
	}
};

int main() {
	int n; scanf("%d", &n);
	std::vector<int> c(n), a(n - 1), b(n - 1), latte;
	std::vector<int> number(n, -1);
	for(int i = 0; i < n; i++) {
		scanf("%d", &c[i]);
		
		latte.push_back(c[i]);
	}
	for(int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--; b[i]--;
		
		number[b[i]] = i;
	}
	sort(begin(latte), end(latte)); latte.erase(unique(begin(latte), end(latte)), end(latte));
	
	std::function<int (int)> getIndex = [&](int v) {
		return lower_bound(begin(latte), end(latte), v) - begin(latte);
	};
	
	//assert(n <= 4000);
	
	std::vector<int> parent(n, -1);
	for(int i = 0; i < n - 1; i++) {
		i64 ans = 0;
		int now = a[i];
		SegmentTree seg(latte.size());
		while(now != -1) {
			int k = getIndex(c[now]);
			ans += seg.get(0, k);
			seg.add(k);
			
			c[now] = c[b[i]];
			now = parent[now];
		}
		parent[b[i]] = a[i];
	
		printf("%lld\n", ans);
	//	for(auto v: c) cout << v << " "; cout << endl;
	}
	
	return 0;
}

Compilation message (stderr)

construction.cpp:37:45: error: expected ')' before '{' token
  i64 get(int a, int b, int k, int l, int r) {
                                             ^
construction.cpp: In member function 'void SegmentTree::add(i64 (*)(int, int, int, int, int))':
construction.cpp:38:6: error: 'b' was not declared in this scope
   if(b <= l || r <= a) return 0;
      ^
construction.cpp:38:11: error: 'l' was not declared in this scope
   if(b <= l || r <= a) return 0;
           ^
construction.cpp:38:16: error: 'r' was not declared in this scope
   if(b <= l || r <= a) return 0;
                ^
construction.cpp:38:21: error: 'a' was not declared in this scope
   if(b <= l || r <= a) return 0;
                     ^
construction.cpp:38:31: error: return-statement with a value, in function returning 'void' [-fpermissive]
   if(b <= l || r <= a) return 0;
                               ^
construction.cpp:39:6: error: 'a' was not declared in this scope
   if(a <= l && r <= b) return seg[k];
      ^
construction.cpp:39:11: error: 'l' was not declared in this scope
   if(a <= l && r <= b) return seg[k];
           ^
construction.cpp:39:16: error: 'r' was not declared in this scope
   if(a <= l && r <= b) return seg[k];
                ^
construction.cpp:39:21: error: 'b' was not declared in this scope
   if(a <= l && r <= b) return seg[k];
                     ^
construction.cpp:39:35: error: 'k' was not declared in this scope
   if(a <= l && r <= b) return seg[k];
                                   ^
construction.cpp:39:36: error: return-statement with a value, in function returning 'void' [-fpermissive]
   if(a <= l && r <= b) return seg[k];
                                    ^
construction.cpp:41:15: error: 'a' was not declared in this scope
   i64 L = get(a, b, 2 * k + 1, l, (l + r) >> 1);
               ^
construction.cpp:41:18: error: 'b' was not declared in this scope
   i64 L = get(a, b, 2 * k + 1, l, (l + r) >> 1);
                  ^
construction.cpp:41:25: error: 'k' was not declared in this scope
   i64 L = get(a, b, 2 * k + 1, l, (l + r) >> 1);
                         ^
construction.cpp:41:32: error: 'l' was not declared in this scope
   i64 L = get(a, b, 2 * k + 1, l, (l + r) >> 1);
                                ^
construction.cpp:41:40: error: 'r' was not declared in this scope
   i64 L = get(a, b, 2 * k + 1, l, (l + r) >> 1);
                                        ^
construction.cpp:43:14: error: return-statement with a value, in function returning 'void' [-fpermissive]
   return L + R;
              ^
construction.cpp: In member function 'i64 SegmentTree::get(int, int)':
construction.cpp:46:28: error: no matching function for call to 'SegmentTree::get(int&, int&, int, int, int&)'
   return get(a, b, 0, 0, sz);
                            ^
construction.cpp:45:6: note: candidate: i64 SegmentTree::get(int, int)
  i64 get(int a, int b) {
      ^~~
construction.cpp:45:6: note:   candidate expects 2 arguments, 5 provided
construction.cpp: In function 'int main()':
construction.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; scanf("%d", &n);
         ~~~~~^~~~~~~~~~
construction.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &c[i]);
   ~~~~~^~~~~~~~~~~~~
construction.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~