Submission #45631542


Source Code Expand

// Problem: E - Somen Nagashi
// Contest: AtCoder - Toyota Programming Contest 2023#5(AtCoder Beginner Contest 320)
// URL: https://atcoder.jp/contests/abc320/tasks/abc320_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
const double PI = 4*atan(1);
template<typename T>
void chmax(T& a, T const b) { a = max(a, b); }
template<typename T>
void chmin(T& a, T const b) { a = min(a, b); }
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 2e6+10;

int n, m;
ll t[MAX_N], w[MAX_N];
ll s[MAX_N], ans[MAX_N];

int N;
ll seg_tree[4*MAX_N];


void init()
{
	N=1;
	while(N < n) N *= 2;
}

ll query(int a, int b, int k, int l, int r)
{
	if(r<=a||b<=l) return LINF;
	else if(a<=l&&r<=b) return seg_tree[k];
	else{
		int mid=(l+r)/2;
		auto le = query(a, b, 2*k+1, l,  mid);
		auto ri = query(a, b, 2*k+2, mid, r);
		return min(le,ri);
	}
}

ll query(int r)
{
	return query(0,r+1,0,0,N);
}
 
int get(ll target)
{
	// first idx such that time <= t
	if(query(n-1) > target) return n;
	int lo=-1, hi=n-1;
	while(lo + 1 < hi){
		int mid = (lo+hi)/2;
		if(query(mid) <= target) hi = mid;
		else lo = mid;
	}
	return hi;
}
 
void update(int idx, ll val)
{
	idx += N - 1;
	seg_tree[idx] = val;
	while(idx > 0) {
		idx = (idx - 1)/2;
		seg_tree[idx] = min(seg_tree[idx*2+1],seg_tree[idx*2+2]);
	}
}

void solve()
{
	init();
	for(int i=0;i<m;++i){
		int idx = get(t[i]);
		if(idx >= n) continue;
		ans[idx] += w[i];
		update(idx, s[i]+t[i]);
	}
	for(int i=0;i<n;++i) cout<<ans[i]<<'\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> m;
	for(int i=0;i<m;++i) cin >> t[i] >> w[i] >> s[i];
	solve();
	return 0;
}

Submission Info

Submission Time
Task E - Somen Nagashi
User zzar
Language C++ 20 (gcc 12.2)
Score 475
Code Size 2076 Byte
Status AC
Exec Time 381 ms
Memory 13008 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 41
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 232 ms 8376 KiB
random_02.txt AC 381 ms 8392 KiB
random_03.txt AC 85 ms 8180 KiB
random_04.txt AC 217 ms 8444 KiB
random_05.txt AC 150 ms 6696 KiB
random_06.txt AC 197 ms 6176 KiB
random_07.txt AC 124 ms 6444 KiB
random_08.txt AC 305 ms 7272 KiB
random_09.txt AC 233 ms 8504 KiB
random_10.txt AC 380 ms 8516 KiB
random_11.txt AC 220 ms 8496 KiB
random_12.txt AC 368 ms 8392 KiB
random_13.txt AC 121 ms 6104 KiB
random_14.txt AC 86 ms 4576 KiB
random_15.txt AC 145 ms 7256 KiB
random_16.txt AC 34 ms 4168 KiB
random_17.txt AC 122 ms 8484 KiB
random_18.txt AC 40 ms 8256 KiB
random_19.txt AC 76 ms 6604 KiB
random_20.txt AC 11 ms 4436 KiB
random_21.txt AC 221 ms 8320 KiB
random_22.txt AC 207 ms 8316 KiB
random_23.txt AC 216 ms 8160 KiB
random_24.txt AC 40 ms 7416 KiB
random_25.txt AC 124 ms 8412 KiB
random_26.txt AC 91 ms 8304 KiB
random_27.txt AC 123 ms 8428 KiB
random_28.txt AC 23 ms 5264 KiB
random_29.txt AC 220 ms 8196 KiB
random_30.txt AC 182 ms 8204 KiB
random_31.txt AC 104 ms 5780 KiB
random_32.txt AC 1 ms 3520 KiB
random_33.txt AC 362 ms 13008 KiB
random_34.txt AC 28 ms 8208 KiB
random_35.txt AC 33 ms 8324 KiB
random_36.txt AC 230 ms 9432 KiB
random_37.txt AC 231 ms 9348 KiB
random_38.txt AC 297 ms 10608 KiB
sample_01.txt AC 1 ms 3484 KiB
sample_02.txt AC 1 ms 3668 KiB
sample_03.txt AC 1 ms 3548 KiB