#include <bits/stdc++.h>
using namespace std;
#define el "\n"
#define FOR(i,a,b) for(int i = (a), _b = (b); i <= _b; i++)
#define FORD(i,a,b) for(int i = (a), _b = (b); i >= _b; i--)
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define lg(x) __lg(x)
#define alla(a,n) a+1,a+n+1
#define ll long long
template <class T> bool maxi(T &x, T y) { if(x < y) { x = y ; return true ;} return false;}
template <class T> bool mini(T &x, T y) { if(x > y) { x = y ; return true ;} return false;}
const int N = 2e5 + 2;
struct Queries
{
int x, y, w;
} E[N];
int n, m;
void inp()
{
cin >> n >> m;
FOR(i, 1, m) {
int x, y, w; cin >> x >> y >> w;
E[i] = {x, y, w};
}
}
namespace subtask_1
{
int st[4 * N], lz[4 * N];
void push(int id, int val)
{
st[id] += val;
lz[id] += val;
}
void down(int id)
{
if(lz[id]) {
int val = lz[id];
push(id << 1, val);
push(id << 1 | 1, val);
lz[id] = 0;
}
}
void upd(int id, int l, int r, int u, int v, int val)
{
if(r < u || v < l) return;
if(u <= l && r <= v) {
push(id, val);
return;
}
int mid = (r + l) >> 1;
down(id);
upd(id << 1, l, mid, u, v, val);
upd(id << 1 | 1, mid + 1, r, u, v, val);
st[id] = max(st[id << 1], st[id << 1 | 1]);
}
void slv()
{
FOR(i, 1, m) {
auto [x, y, w] = E[i];
if(x > y) swap(x, y);
int m1 = y - x;
int m2 = x + (n - y);
if(m1 < m2) {
upd(1, 1, n, x, y - 1, w);
}
else {
upd(1, 1, n, 1, x, 1);
upd(1, 1, n, y + 1, n, w);
}
}
cout << (st[1] + 1) / 2 << el;
}
}
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define __Azul__ "arranging_tickets"
if(fopen(__Azul__".inp", "r")) {
freopen(__Azul__".inp", "r", stdin);
freopen(__Azul__".out", "w", stdout);
}
bool qs = 0;
int T = 1;
if(qs) cin >> T;
while(T--) {
inp();
subtask_1::slv();
}
cerr << "\nTime" << 0.001 * clock() << "s "; return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
arranging_tickets.cpp:90:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
90 | main()
| ^~~~
arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(__Azul__".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
arranging_tickets.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(__Azul__".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |