제출 #145703

#제출 시각아이디문제언어결과실행 시간메모리
145703Minnakhmetov모임들 (IOI18_meetings)C++14
컴파일 에러
0 ms0 KiB
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int INF = 1e9;
const int N1 = 5005, N2 = 1e5 + 5, K = 21;
ll lp[N1][N1], rp[N1][N1];
int n, q;
vector<int> a;

vector<ll> slow(vector<int> L, vector<int> R) {
	for (int i = 0; i < n; i++) {
  		ll cur = 0;
  		int mx = a[i];
  		for (int j = i - 1; j >= 0; j--) {
  			mx = max(mx, a[j]);
  			cur += mx;
  			lp[j][i] = cur;
  		}

  		cur = 0;
  		mx = a[i];

  		for (int j = i + 1; j < n; j++) {
  			mx = max(mx, a[j]);
  			cur += mx;
  			rp[i][j] = cur;
  		}
  	}


  	vector<ll> ans(q);

  	for (int i = 0; i < q; i++) {
  		ll mn = INF;
  		for (int j = L[i]; j <= R[i]; j++) {
  			mn = min(mn, lp[L[i]][j] + rp[j][R[i]] + a[j]);
  		}
  		ans[i] = mn;
  	}
  	return ans;
}


struct Node {
	int mx, lp[K], rp[K], val[K][K];

	Node() {
		for (int i = 0; i < K; i++) {
			for (int j = 0; j < K; j++) {
				val[i][j] = INF;
			}
		}
		fill(lp, lp + K, 0);
		fill(rp, rp + K, 0);
		mx = 0;
	}
} t[N2 * 4];

void upd(ll &a, ll b) {
	a = min(a, b);
}

Node operator + (Node a, Node b) {
	Node c;
	c.mx = max(a.mx, b.mx);

	for (int i = 0; i < K; i++) {
		c.rp[i] = b.rp[i] + a.rp[max(i, b.mx)];
		c.lp[i] = a.lp[i] + b.lp[max(i, a.mx)];
	}

	for (int i = 0; i < K; i++) {
		for (int j = 0; j < K; j++) {
			upd(c.val[i][max(j, b.mx)], a.val[i][j] + b.lp[j]);
			upd(c.val[max(i, a.mx)][j], b.val[i][j] + a.rp[i]);
		}
	}

	return c;
}


void build(int v, int L, int R) {
	if (L == R) {
		t[v].val[a[L]][a[L]] = a[L];
		for (int i = 0; i <= a[L]; i++)
			t[v].lp[i] = t[v].rp[i] = a[L];
		for (int i = a[L] + 1; i < K; i++) {
			t[v].lp[i] = t[v].rp[i] = i;
		}
		t[v].mx = a[L];
	}
	else {
		int m = (L + R) >> 1;
		build(v * 2, L, m);
		build(v * 2 + 1, m + 1, R);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
	// cout << L << " " << R << " :\n";
	// for (int i = 0; i < 2; i++) {
	// 	for (int j = 0; j < 2; j++) {
	// 		cout << i << " " << j << " = " << t[v].val[i][j] << "\n";
	// 	}
	// }
	// cout << "\n\n";
	// for (int i = 0; i < 2; i++)
	// 	cout << t[v].lp[i] << " ";
	// cout << "\n";
	// for (int i = 0; i < 2; i++)
	// 	cout << t[v].rp[i] << " ";
	// cout << "\n";
	// cout << "\n";
}

Node que(int l, int r, int v, int L, int R) {
	if (l > r)
		return Node();
	if (l == L && r == R)
		return t[v];
	int m = (L + R) >> 1;
	return que(l, min(m, r), v * 2, L, m) +
		que(max(m + 1, l), r, v * 2 + 1, m + 1, R);
}

vector<ll> solveWhenLessThan20(vector<int> L, vector<int> R) {
	build(1, 0, n - 1);

	vector<ll> ans(q, 0);

	for (int i = 0; i < q; i++) {
		auto res = que(L[i], R[i], 1, 0, n - 1);
		ll mn = INF;
		for (int x = 0; x < K; x++) {
			for (int y = 0; y < K; y++) {
				mn = min(mn, res.val[x][y]);
			}
		}
		ans[i] = mn;
	}
	return ans;
}

std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
                                     std::vector<int> R) {
	a = H;
	n = a.size(), q = L.size();

  	if (n < N1 && q < N1) {
  		return slow(L, R); 
  	}

  	return solveWhenLessThan20(L, R);
}

컴파일 시 표준 에러 (stderr) 메시지

meetings.cpp: In function 'Node operator+(Node, Node)':
meetings.cpp:78:29: error: cannot bind non-const lvalue reference of type 'long long int&' to an rvalue of type 'long long int'
    upd(c.val[i][max(j, b.mx)], a.val[i][j] + b.lp[j]);
        ~~~~~~~~~~~~~~~~~~~~~^
meetings.cpp:63:6: note:   initializing argument 1 of 'void upd(long long int&, long long int)'
 void upd(ll &a, ll b) {
      ^~~
meetings.cpp:79:29: error: cannot bind non-const lvalue reference of type 'long long int&' to an rvalue of type 'long long int'
    upd(c.val[max(i, a.mx)][j], b.val[i][j] + a.rp[i]);
        ~~~~~~~~~~~~~~~~~~~~~^
meetings.cpp:63:6: note:   initializing argument 1 of 'void upd(long long int&, long long int)'
 void upd(ll &a, ll b) {
      ^~~
meetings.cpp: In function 'std::vector<long long int> solveWhenLessThan20(std::vector<int>, std::vector<int>)':
meetings.cpp:139:31: error: no matching function for call to 'min(long long int&, int&)'
     mn = min(mn, res.val[x][y]);
                               ^
In file included from /usr/include/c++/7/vector:60:0,
                 from meetings.h:3,
                 from meetings.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
meetings.cpp:139:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     mn = min(mn, res.val[x][y]);
                               ^
In file included from /usr/include/c++/7/vector:60:0,
                 from meetings.h:3,
                 from meetings.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
meetings.cpp:139:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     mn = min(mn, res.val[x][y]);
                               ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from meetings.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
meetings.cpp:139:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     mn = min(mn, res.val[x][y]);
                               ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from meetings.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
meetings.cpp:139:31: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     mn = min(mn, res.val[x][y]);
                               ^