Submission #711170

# Submission time Handle Problem Language Result Execution time Memory
711170 2023-03-16T09:07:06 Z myrcella Distributing Candies (IOI21_candies) C++17
8 / 100
129 ms 17120 KB
//by szh
#include<bits/stdc++.h>
#include "candies.h"
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 200010;

int n,m;
int hi[maxn];
vector <int> ans;
vector <ll> anss;

struct Q{
	int l,r,v;
}q[maxn];

vector <int> solve1() {
	rep(i,0,n) ans.pb(0);
	rep(i,0,m) {
		rep(j,q[i].l,q[i].r+1) {
			ans[j] += q[i].v;
			if (ans[j]<0) ans[j]=0;
			if (ans[j]>hi[j]) ans[j] = hi[j];
		}
	}
	return ans;
}

vector <int> solve2(){
	rep(i,0,n) anss.pb(0);
	rep(i,0,m) {
		anss[q[i].l]+=q[i].v;
		if (q[i].r+1<SZ(anss))anss[q[i].r+1]-=q[i].v;
	}
	rep(i,1,n) anss[i] += anss[i-1];
	rep(i,0,n) {
		if (anss[i]>hi[i]) ans.pb(hi[i]);
		else ans.pb(anss[i]);
	}
	return ans;
}

vector <int> solve3() {
	return ans;
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    
    n = SZ(c),m = SZ(l);
    rep(i,0,n) hi[i] = c[i];
    rep(i,0,m) q[i].l = l[i],q[i].r = r[i], q[i].v = v[i];
  //  if (n<=2000) return solve1();
    bool check=true;
    rep(i,1,n) if (c[i]!=c[i-1]) check=false;
    if (check) return solve3();
    check=true;
    rep(i,0,m) if (v[i]<=0) check=false;
    if (check) return solve2();
    //subtask 4
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 13024 KB Output is correct
2 Correct 104 ms 17120 KB Output is correct
3 Correct 129 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -