//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=2e5+5;
vector<int> sg(mxn*4);
vector<int> lazy(mxn*4);
int n,m;
void push(int v){
if(lazy[v]!=0){
sg[v*2]+=lazy[v];
lazy[v*2]+=lazy[v];
sg[v*2+1]+=lazy[v];
lazy[v*2+1]+=lazy[v];
lazy[v]=0;
}
}
void update(int tl,int tr,int val,int l=1,int r=n,int v=1){
if(r<tl or tr<l){
return;
}
if(tl<=l and r<=tr){
sg[v]+=val;
lazy[v]+=val;
return;
}
int mid=(l+r)/2;
if(l<r) push(v);
update(tl,min(mid,tr),val,l,mid,v*2);
update(max(mid+1,tl),tr,val,mid+1,r,v*2+1);
sg[v]=max(sg[v*2],sg[v*2+1]);
}
signed main() {_
cin>>n>>m;
ll ans=0;
vector<vector<pair<pair<int,int>,ll>>> st(n+1);
vector<vector<pair<pair<int,int>,ll>>> en(n+1);
for(int i=0;i<m;i++){
int l,r,c;
cin>>l>>r>>c;
if(l>r) swap(l,r);
st[1].push_back({{l,r-1},c});
en[l].push_back({{l,r-1},c});
st[l].push_back({{1,l-1},c});
st[l].push_back({{r,n},c});
en[r].push_back({{1,l-1},c});
en[r].push_back({{r,n},c});
st[r].push_back({{l,r-1},c});
}
ll mx=0;
for(int i=1;i<=n;i++){
//cout<<i<<'\n';
for(auto v:st[i]){
if(v.f.f>v.f.s) continue;
//cout<<v.f.f<<' '<<v.f.s<<' '<<v.s<<'\n';
update(v.f.f,v.f.s,v.s);
}
for(auto v:en[i]){
if(v.f.f>v.f.s) continue;
//cout<<v.f.f<<' '<<v.f.s<<' '<<-v.s<<'\n';
update(v.f.f,v.f.s,-v.s);
}
int cnt=sg[1];
mx=max(mx,(cnt+1)/2);
}
cout<<mx<<'\n';
return 0;
}
//maybe its multiset not set
//yeeorz
//diaoborz
Compilation message (stderr)
arranging_tickets.cpp: In function 'void setIO(std::string)':
arranging_tickets.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arranging_tickets.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen((s + ".out").c_str(), "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... |