Submission #826822

# Submission time Handle Problem Language Result Execution time Memory
826822 2023-08-16T05:02:12 Z ymm Distributing Candies (IOI21_candies) C++17
100 / 100
4321 ms 9020 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("avx2")

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 0 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 2397 ms 9020 KB Output is correct
2 Correct 2399 ms 8912 KB Output is correct
3 Correct 2396 ms 8824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 68 ms 5048 KB Output is correct
3 Correct 68 ms 5388 KB Output is correct
4 Correct 2277 ms 8872 KB Output is correct
5 Correct 2300 ms 8892 KB Output is correct
6 Correct 2293 ms 8884 KB Output is correct
7 Correct 2253 ms 8864 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 84 ms 4964 KB Output is correct
4 Correct 78 ms 4272 KB Output is correct
5 Correct 4309 ms 8908 KB Output is correct
6 Correct 4282 ms 8892 KB Output is correct
7 Correct 4311 ms 8864 KB Output is correct
8 Correct 4315 ms 8888 KB Output is correct
9 Correct 4321 ms 8888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 2397 ms 9020 KB Output is correct
7 Correct 2399 ms 8912 KB Output is correct
8 Correct 2396 ms 8824 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 68 ms 5048 KB Output is correct
11 Correct 68 ms 5388 KB Output is correct
12 Correct 2277 ms 8872 KB Output is correct
13 Correct 2300 ms 8892 KB Output is correct
14 Correct 2293 ms 8884 KB Output is correct
15 Correct 2253 ms 8864 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 84 ms 4964 KB Output is correct
19 Correct 78 ms 4272 KB Output is correct
20 Correct 4309 ms 8908 KB Output is correct
21 Correct 4282 ms 8892 KB Output is correct
22 Correct 4311 ms 8864 KB Output is correct
23 Correct 4315 ms 8888 KB Output is correct
24 Correct 4321 ms 8888 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 57 ms 4160 KB Output is correct
27 Correct 72 ms 4984 KB Output is correct
28 Correct 2296 ms 8884 KB Output is correct
29 Correct 2275 ms 8876 KB Output is correct
30 Correct 2290 ms 8812 KB Output is correct
31 Correct 2303 ms 8912 KB Output is correct
32 Correct 2521 ms 8820 KB Output is correct