Chtholly_is_cute @ 2023-06-08 17:51:41
TLE on #5,#6
code:
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
#define int long long
const ll mod = 1000000007;
const ll maxn = 100055;
struct node {
ll l, r;
mutable ll v;
node(ll L, ll R = 0, ll V = 0) : l(L), r(R), v(V) {}
bool operator<(const node& a)const {
return l < a.l;
}
};
ll n, v, op, l, r, x;
set<node>odt;
#define IT set<node>::iterator
set<node>::iterator split(int pos) {
set<node>::iterator it = odt.lower_bound(node(pos));
if (it != odt.end() && it->l == pos)return it;
it--;
if (it->r < pos)return odt.end();
ll l = it->l;
ll r = it->r;
ll v = it->v;
odt.erase(it);
odt.insert(node(l, pos - 1, v));
return odt.insert(node(pos, r, v)).first;
}
void add(ll l, ll r, ll x) {
set<node>::iterator itr = split(r + 1), itl = split(l);
for (register set<node>::iterator it = itl; it != itr; it++)it->v += x;
}
void assign(ll l, ll r, ll x) {
set<node>::iterator itr = split(r + 1), itl = split(l);
odt.erase(itl, itr);
odt.insert(node(l, r, x));
}
ll query(ll l, ll r) {
ll maxn = 1099521627776;
maxn *= -1;
set<node>::iterator itr = split(r + 1), itl = split(l);
for (register set<node>::iterator it = itl; it != itr; it++) {
maxn = max(maxn, it->v);
}
return maxn;
}
signed main() {
int n, m;
scanf("%lld%lld", &n, &m);
for (register int i = 1; i <= n; i++) {
scanf("%lld", &v);
odt.insert(node(i, i, v));
}
for (register int i = 1; i <= m; i++) {
scanf("%lld", &op);
if (op == 1) {
scanf("%lld%lld%lld", &l, &r, &x);
assign(l, r, x);
}
else if (op == 2) {
scanf("%lld%lld%lld", &l, &r, &x);
add(l, r, x);
}
else {
scanf("%lld%lld", &l, &r);
cout << query(l, r) << endl;
}
}
return 0;
}
by As_Snow @ 2023-06-08 18:08:13
@andyzhu444 ODT挂了正常吧,毕竟其很容易被卡掉
by 我是一个小号 @ 2023-06-08 18:28:09
线段树……它不香吗?
by Chtholly_is_cute @ 2023-06-08 21:04:28
@我是一个小号 我不会线段树
by TimeLimitEnough @ 2023-08-17 21:02:09
@andyzhu444 不保证数据随机的话,珂朵莉树复杂度是不正确的,怎么会过呢