Submission #826820

# Submission time Handle Problem Language Result Execution time Memory
826820 2023-08-16T05:00:56 Z ymm Distributing Candies (IOI21_candies) C++17
100 / 100
2513 ms 12256 KB
#include "candies.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
using namespace std;

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

const int inf = 1e9+1;
const int N = 200'010;
const int S = 2048;
int a[N], c[N];

void add(int l, int r, int x)
{
	Loop (i,l,r)
		a[i] = (a[i] + x > c[i]? c[i]: a[i] + x);
}
void sub(int l, int r, int x)
{
	Loop (i,l,r)
		a[i] = (a[i] - x < 0? 0: a[i] - x);
}
void addsub(int l, int r, int x, int y)
{
	Loop (i,l,r) {
		a[i] = (a[i] + x > c[i]? c[i]: a[i] + x);
		a[i] = (a[i] - y < 0? 0: a[i] - y);
	}
}
void subadd(int l, int r, int x, int y)
{
	Loop (i,l,r) {
		a[i] = (a[i] - x < 0? 0: a[i] - x);
		a[i] = (a[i] + y > c[i]? c[i]: a[i] + y);
	}
}
void up(int l, int r, int x)
{
	if (x > 0)
		add(l, r, x);
	else
		sub(l, r, -x);
}
void upup(int l, int r, int x, int y)
{
	if (x >  0 && y >  0)
		add(l, r, min(inf, x+y));
	if (x <= 0 && y <= 0)
		sub(l, r, min(inf, -(x+y)));
	if (x >  0 && y <= 0)
		addsub(l, r, x, -y);
	if (x <= 0 && y >  0)
		subadd(l, r, -x, y);
}

std::vector<int> distribute_candies(std::vector<int> _c, std::vector<int> ql,
                                    std::vector<int> qr, std::vector<int> qv) {
    int n = _c.size();
    int q = ql.size();
    for (int &x : qr)
	    ++x;
    if (q%2) {
	    ql.push_back(0);
	    qr.push_back(1);
	    qv.push_back(0);
	    ++q;
    }
    Loop (i,0,n)
	    c[i] = _c[i];
    for (int L = 0; L < n; L += S) {
	    int R = min<int>(L+S, n);
	    for (int i = 0; i < q; i += 2) {
		    int l0 = ql[i], l1 = ql[i+1];
		    int r0 = qr[i], r1 = qr[i+1];
		    int v0 = qv[i], v1 = qv[i+1];
		    if (l0 <= L && R <= r0 && l1 <= L && R <= r1) {
			    upup(L, R, v0, v1);
		    } else {
			    up(max(l0, L), min(r0, R), v0);
			    up(max(l1, L), min(r1, R), v1);
		    }
	    }
    }
    return vector<int>(a, a+n);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1448 ms 12164 KB Output is correct
2 Correct 1439 ms 12168 KB Output is correct
3 Correct 1443 ms 12212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 64 ms 8012 KB Output is correct
3 Correct 51 ms 7476 KB Output is correct
4 Correct 1365 ms 12176 KB Output is correct
5 Correct 1359 ms 12128 KB Output is correct
6 Correct 1383 ms 12224 KB Output is correct
7 Correct 1326 ms 12168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 65 ms 7632 KB Output is correct
4 Correct 59 ms 5548 KB Output is correct
5 Correct 2368 ms 12188 KB Output is correct
6 Correct 2405 ms 12152 KB Output is correct
7 Correct 2454 ms 12236 KB Output is correct
8 Correct 2447 ms 12172 KB Output is correct
9 Correct 2513 ms 12240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1448 ms 12164 KB Output is correct
7 Correct 1439 ms 12168 KB Output is correct
8 Correct 1443 ms 12212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 64 ms 8012 KB Output is correct
11 Correct 51 ms 7476 KB Output is correct
12 Correct 1365 ms 12176 KB Output is correct
13 Correct 1359 ms 12128 KB Output is correct
14 Correct 1383 ms 12224 KB Output is correct
15 Correct 1326 ms 12168 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 65 ms 7632 KB Output is correct
19 Correct 59 ms 5548 KB Output is correct
20 Correct 2368 ms 12188 KB Output is correct
21 Correct 2405 ms 12152 KB Output is correct
22 Correct 2454 ms 12236 KB Output is correct
23 Correct 2447 ms 12172 KB Output is correct
24 Correct 2513 ms 12240 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 49 ms 5404 KB Output is correct
27 Correct 61 ms 7640 KB Output is correct
28 Correct 1348 ms 12176 KB Output is correct
29 Correct 1376 ms 12256 KB Output is correct
30 Correct 1350 ms 12216 KB Output is correct
31 Correct 1354 ms 12208 KB Output is correct
32 Correct 1347 ms 12168 KB Output is correct