답안 #682457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682457 2023-01-16T09:06:31 Z smartmonky 거래 (IZhO13_trading) C++14
100 / 100
291 ms 34948 KB
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
 
using namespace std;
 
const int N = 3e5 + 1;
int t[N * 8], add[N * 8], ans[N * 8];
int lg, rg, x;
int n;
void push(int v, int tl, int tr){
	t[v] = max(t[v], add[v]);
	int mid = (tl + tr) >> 1;
	add[v * 2 + 1] = max(add[v * 2 + 1], add[v]);
	add[v * 2] = max(add[v * 2], add[v] - tr + mid);
}
 
void update(int v = 1, int tl = 1, int tr = n){
	push(v, tl, tr);
	if(tl > rg || tr < lg)
		return;
	if(tl >= lg && tr <= rg){
		add[v] = max(add[v], x + tr - lg);
		push(v, tl, tr);
		return;
	}
	int mid = (tl + tr) >> 1;
	update(v * 2, tl, mid);
	update(v * 2 + 1, mid + 1, tr);
}
void get(int v = 1, int tl = 1, int tr = n){
	push(v, tl, tr);
	if(tl == tr){
		ans[tl] = t[v];
		return;	
	}else{
		int mid = (tl + tr) >> 1;
		get(v * 2, tl, mid);
		get(v * 2 + 1, mid + 1, tr);
	}
}
main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    int m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
		cin >> lg >> rg >> x;
		update();
	}
	get();
	for(int i = 1; i <= n; i++){
		cout << ans[i] <<" ";
	}
}

Compilation message

trading.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 131 ms 17436 KB Output is correct
8 Correct 176 ms 18244 KB Output is correct
9 Correct 181 ms 18320 KB Output is correct
10 Correct 173 ms 18440 KB Output is correct
11 Correct 222 ms 19388 KB Output is correct
12 Correct 183 ms 19480 KB Output is correct
13 Correct 192 ms 19932 KB Output is correct
14 Correct 250 ms 19852 KB Output is correct
15 Correct 238 ms 20684 KB Output is correct
16 Correct 255 ms 20824 KB Output is correct
17 Correct 265 ms 31444 KB Output is correct
18 Correct 273 ms 33832 KB Output is correct
19 Correct 281 ms 33576 KB Output is correct
20 Correct 291 ms 34948 KB Output is correct