区间修改想到树状数组或者线段树或者差分,但是看到数据1e9,发现都不行,那么考虑是诈骗题,然后发现x,y都是正的,那么没有比第一个更优的策略.
然后就wa了.......
看题目注意求绝对值,要把最后一个也考虑到
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
int q;
cin>>n>>q;
int od,x,y;
int res1= 0;
int res2 = 0;
for(int i =1; i<= q; i++)
{
cin>>od>>x>>y;
if(od==1)
{
res1 += y;
}
else if(x == n)
{
res1 -= y;
}
if(od == 2)
{
res2 -= y;
}
if(od == 1 && x == n)
{
res2 += y;
}
}
cout<<max(abs(res1),abs(res2));
return 0;
}