Submission #545855

# Submission time Handle Problem Language Result Execution time Memory
545855 2022-04-05T15:21:15 Z fuad27 Distributing Candies (IOI21_candies) C++17
8 / 100
117 ms 12972 KB
#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200'010;
long long fen[MAXN];
void upd(int at, long long val) {
	at++;
	while(at < MAXN) {
		fen[at]+=val;


		at+=at&(-at);
	}
}
long long query(int r) {
	long long sum = 0;
	r++;
	while(r > 0) {
		sum+=fen[r];
		r-=r&(-r);
	}
	return sum;
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n);
	for(int i = 0;i<MAXN;i++)fen[i] =0;
	for(int i = 0;i<n;i++) {
		upd(l[i], v[i]);
		upd(r[i]+1, -v[i]);
	}
	for(int i = 0;i<n;i++) {
		s[i] = min((long long)c[i], query(i));
	}
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Incorrect 1 ms 1848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 117 ms 8812 KB Output is correct
2 Correct 112 ms 12972 KB Output is correct
3 Correct 108 ms 12748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1748 KB Output is correct
2 Incorrect 1 ms 1848 KB Output isn't correct
3 Halted 0 ms 0 KB -