답안 #831066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831066 2023-08-19T16:46:49 Z NothingXD 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx")

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 2e5 + 10;
const int S = 2048

int n, q, a[maxn], c[maxn], l[maxn], r[maxn], v[maxn];

void add1(int l, int r, int x){
//	debug(1, l, r, x);
	for (int i = l; i <= r; i++){
		a[i] = (a[i]+x > c[i]? c[i]: a[i]+x);
	}
}

void add2(int l, int r, int x){
//	debug(2, l, r, x);
	for (int i = l; i <= r; i++){
		a[i] = (a[i]+x < 0? 0: a[i]+x);
	}
}

void add3(int l, int r, int x, int y){
//	debug(3, l, r, x, y);
	for (int i = l; i <= r; i++){
		a[i] = (a[i]+x > c[i]? c[i]: a[i]+x);
//		debug(i, a[i]);
		a[i] = (a[i]+y < 0? 0: a[i]+y);
//		debug(i, a[i]);
	}
}

void add4(int l, int r, int x, int y){
	//debug(4, l, r, x, y);
	for (int i = l; i <= r; i++){
		a[i] = (a[i]+x < 0? 0: a[i]+x);
		a[i] = (a[i]+y > c[i]? c[i]: a[i]+y);
	}
}

vector<int> distribute_candies(vector<int> C, vector<int> L, vector<int> R, vector<int> V) {
	n = C.size();
	q = L.size();
	for (int i = 0; i < n; i++){
		c[i] = C[i];
	}
	for (int i = 0; i < q; i++){
		l[i] = L[i];
		r[i] = R[i];
		v[i] = V[i];
	}
	for (int st = 0; st < n; st += S){
	for (int i = 0; i < q; i += 2){
		if (i + 1 == q){
			int L = max(st, l[i]);
			int R = min(st+S-1, r[i]);
			if (v[i] > 0) add1(L, R, v[i]);
			if (v[i] < 0) add2(L, R, v[i]);
			break;
		}
		int L1 = max(st, l[i]);
		int R1 = min(st+S-1, r[i]);
		int L2 = max(st, l[i+1]);
		int R2 = min(st+S-1, r[i+1]);
		if (v[i] == 0 && v[i+1] == 0) continue;
		if (v[i] >= 0 && v[i+1] >= 0){
			add1(L1, min(R1, L2-1), v[i]);
			add1(L2, min(R2, L1-1), v[i+1]);
			add1(max(L1, L2), min(R1, R2), min(v[i]+v[i+1],(int)1e9));
			add1(max(L1, R2+1), R1, v[i]);
			add1(max(L2, R1+1), R2, v[i+1]);
		}
		else if (v[i] <= 0 && v[i+1] <= 0){
			add2(L1, min(R1, L2-1), v[i]);
			add2(L2, min(R2, L1-1), v[i+1]);
			add2(max(L1, L2), min(R1, R2), max(v[i]+v[i+1],(int)-1e9));
			add2(max(L1, R2+1), R1, v[i]);
			add2(max(L2, R1+1), R2, v[i+1]);
		}
		else if (v[i] >= 0 && v[i+1] <= 0){
			add1(L1, min(R1, L2-1), v[i]);
			add2(L2, min(R2, L1-1), v[i+1]);
			add3(max(L1, L2), min(R1, R2), v[i], v[i+1]);
			add1(max(L1, R2+1), R1, v[i]);
			add2(max(L2, R1+1), R2, v[i+1]);
		}
		else{
			add2(L1, min(R1, L2-1), v[i]);
			add1(L2, min(R2, L1-1), v[i+1]);
			add4(max(L1, L2), min(R1, R2), v[i], v[i+1]);
			add2(max(L1, R2+1), R1, v[i]);
			add1(max(L2, R1+1), R2, v[i+1]);
		}
	}
	}
	vector<int> ans;
	for (int i = 0; i < n; i++){
		ans.push_back(a[i]);
	}
	return ans;
}

Compilation message

candies.cpp:29:1: error: expected ',' or ';' before 'int'
   29 | int n, q, a[maxn], c[maxn], l[maxn], r[maxn], v[maxn];
      | ^~~
candies.cpp: In function 'void add1(int, int, int)':
candies.cpp:34:3: error: 'a' was not declared in this scope
   34 |   a[i] = (a[i]+x > c[i]? c[i]: a[i]+x);
      |   ^
candies.cpp:34:20: error: 'c' was not declared in this scope
   34 |   a[i] = (a[i]+x > c[i]? c[i]: a[i]+x);
      |                    ^
candies.cpp: In function 'void add2(int, int, int)':
candies.cpp:41:3: error: 'a' was not declared in this scope
   41 |   a[i] = (a[i]+x < 0? 0: a[i]+x);
      |   ^
candies.cpp: In function 'void add3(int, int, int, int)':
candies.cpp:48:3: error: 'a' was not declared in this scope
   48 |   a[i] = (a[i]+x > c[i]? c[i]: a[i]+x);
      |   ^
candies.cpp:48:20: error: 'c' was not declared in this scope
   48 |   a[i] = (a[i]+x > c[i]? c[i]: a[i]+x);
      |                    ^
candies.cpp: In function 'void add4(int, int, int, int)':
candies.cpp:58:3: error: 'a' was not declared in this scope
   58 |   a[i] = (a[i]+x < 0? 0: a[i]+x);
      |   ^
candies.cpp:59:20: error: 'c' was not declared in this scope
   59 |   a[i] = (a[i]+y > c[i]? c[i]: a[i]+y);
      |                    ^
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:64:2: error: 'n' was not declared in this scope
   64 |  n = C.size();
      |  ^
candies.cpp:65:2: error: 'q' was not declared in this scope
   65 |  q = L.size();
      |  ^
candies.cpp:67:3: error: 'c' was not declared in this scope
   67 |   c[i] = C[i];
      |   ^
candies.cpp:70:3: error: 'l' was not declared in this scope
   70 |   l[i] = L[i];
      |   ^
candies.cpp:71:3: error: 'r' was not declared in this scope
   71 |   r[i] = R[i];
      |   ^
candies.cpp:72:3: error: 'v' was not declared in this scope
   72 |   v[i] = V[i];
      |   ^
candies.cpp:77:20: error: 'l' was not declared in this scope
   77 |    int L = max(st, l[i]);
      |                    ^
candies.cpp:78:24: error: 'r' was not declared in this scope
   78 |    int R = min(st+S-1, r[i]);
      |                        ^
candies.cpp:79:8: error: 'v' was not declared in this scope
   79 |    if (v[i] > 0) add1(L, R, v[i]);
      |        ^
candies.cpp:80:8: error: 'v' was not declared in this scope
   80 |    if (v[i] < 0) add2(L, R, v[i]);
      |        ^
candies.cpp:83:20: error: 'l' was not declared in this scope
   83 |   int L1 = max(st, l[i]);
      |                    ^
candies.cpp:84:24: error: 'r' was not declared in this scope
   84 |   int R1 = min(st+S-1, r[i]);
      |                        ^
candies.cpp:87:7: error: 'v' was not declared in this scope
   87 |   if (v[i] == 0 && v[i+1] == 0) continue;
      |       ^
candies.cpp:88:7: error: 'v' was not declared in this scope
   88 |   if (v[i] >= 0 && v[i+1] >= 0){
      |       ^
candies.cpp:120:17: error: 'a' was not declared in this scope
  120 |   ans.push_back(a[i]);
      |                 ^