QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397811#8229. 栈PYD10 18ms9560kbC++145.3kb2024-04-24 17:11:402024-04-24 17:11:41

Judging History

你现在查看的是最新测评结果

  • [2024-04-24 17:11:41]
  • 评测
  • 测评结果:0
  • 用时:18ms
  • 内存:9560kb
  • [2024-04-24 17:11:40]
  • 提交

answer

#include <set>
#include <map>
#include <list>
#include <queue>
#include <cmath>
#include <time.h>
#include <random>
#include <bitset>
#include <vector>
#include <cstdio>
#include <stdio.h>
#include <iomanip>
#include <assert.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mk make_pair
#define fi first
#define se second

inline int read(){
	int t = 0,f = 1;
	register char c = getchar();
	while (c < 48 || c > 57) f = (c == '-') ? (-1) : (f),c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return f * t;
}

const int N = 1e5 + 10;
int n,m,tmpcnt,tmp[N],tl[N],tr[N],q1cnt,q1[N];
bool isqry[N];
ll ans[N];

struct OP{
	int i,t,a,b;
}ops[N];

vector <int> mvec[N],qvec[N];

inline pair<ll,ll> c1(pair<ll,ll> lhs,pair<ll,ll> rhs){
	return mk(max(rhs.fi,lhs.fi + rhs.se),lhs.se + rhs.se);
}

inline pair<ll,ll> c2(pair<ll,ll> lhs,pair<ll,ll> rhs){
	return mk(lhs.fi + rhs.fi,min(lhs.se,lhs.fi + rhs.se));
}

namespace TR{
	pair<ll,ll> ad[N << 1];//mx,ad
	pair<ll,ll> mn[N << 1];//sum,mn
	int val[N << 1];
	ll ar[N << 1];
	ll calc(int i,int l,int r,ll x){//x <= 0
		if (l == r) return val[i] * max(0ll,ad[i].se + x);
		int mid = (l + r) >> 1;
		ll rsz = max(ad[i << 1 | 1].fi,ad[i << 1 | 1].se);
		if (rsz + x >= 0) return ar[i << 1] + calc(i << 1 | 1,mid + 1,r,x);
		else return calc(i << 1,l,mid,min(0ll,mn[i << 1 | 1].se) + x + rsz);
	}
	void pushup(int i,int l,int r){
		if (l == r) return ;
		int mid = (l + r) >> 1;
		ad[i] = c1(ad[i << 1],ad[i << 1 | 1]);
		mn[i] = c2(mn[i << 1],mn[i << 1 | 1]);
		ar[i << 1] = calc(i << 1,l,mid,min(0ll,mn[i << 1 | 1].se));
	}
	void modify(int i,int l,int r,int p,ll v1,int v2){
		if (l == r){
			if (v1 == 0) ad[i] = mk(0,0),mn[i] = mk(0,0),val[i] = 0;
			if (v1 > 0) ad[i] = mk(0,v1),mn[i] = mk(v1,v1),val[i] = v2;
			if (v1 < 0) ad[i] = mk(0,v1),mn[i] = mk(v1,v1),val[i] = 0;
			return ;
		}
		int mid = (l + r) >> 1;
		if (p <= mid) modify(i << 1,l,mid,p,v1,v2);
		else modify(i << 1 | 1,mid + 1,r,p,v1,v2);
		pushup(i,l,r);
	}
	pair<ll,ll> querysz(int i,int l,int r,int ql,int qr){
		if (ql > qr) return mk(0,0);
		if (l >= ql && r <= qr) return ad[i];
		int mid = (l + r) >> 1;pair<ll,ll> ans = mk(0,0);
		if (ql <= mid) ans = c1(ans,querysz(i << 1,l,mid,ql,qr));
		if (qr > mid) ans = c1(ans,querysz(i << 1 | 1,mid + 1,r,ql,qr));
		return ans;
	}
	pair<ll,ll> querymn(int i,int l,int r,int ql,int qr){
		if (ql > qr) return mk(0,0);
		if (l >= ql && r <= qr) return mn[i];
		int mid = (l + r) >> 1;pair<ll,ll> ans = mk(0,0);
		if (ql <= mid) ans = c2(ans,querymn(i << 1,l,mid,ql,qr));
		if (qr > mid) ans = c2(ans,querymn(i << 1 | 1,mid + 1,r,ql,qr));
		return ans;
	}
	void query(int i,int l,int r,int ql,int qr){
		if (ql > qr) return ;
		if (l >= ql && r <= qr) {++tmpcnt,tmp[tmpcnt] = i,tl[tmpcnt] = l,tr[tmpcnt] = r;return ;}
		int mid = (l + r) >> 1;
		if (ql <= mid) query(i << 1,l,mid,ql,qr);
		if (qr > mid) query(i << 1 | 1,mid + 1,r,ql,qr);
	}
}

ll query(int tim,int pos){
	int l = 0,r = tim;
	while (l < r){
		int mid = (l + r) >> 1;
		auto p = TR::querysz(1,1,m,1,mid),s = TR::querymn(1,1,m,mid + 1,tim);
		ll v1 = max(p.fi,p.se),v2 = min(0ll,s.se);
		if (v1 + v2 >= 0) r = mid;
		else l = mid + 1;
	}
	if (l == tim) return 0;
	int p1 = l + 1;
	l = 0,r = tim;
	while (l < r){
		int mid = (l + r) >> 1;
		auto p = TR::querysz(1,1,m,1,mid);
		auto s = TR::querymn(1,1,m,mid + 1,tim);
		ll v1 = max(p.fi,p.se),v2 = min(0ll,s.se);
		if (v1 + v2 >= pos) r = mid;
		else l = mid + 1;
	}
	int p2 = l - 1;
	ll ans = 0;
	auto p = TR::querysz(1,1,m,1,l - 1);
	ans += (pos - max(p.fi,p.se)) * ops[l].b;
	tmpcnt = 0;TR::query(1,1,m,p1,p2);
	ll lst = 0;
	for (int i = tmpcnt;i >= 1;i--){
		ans += TR::calc(tmp[i],tl[i],tr[i],lst);
		lst = max(TR::ad[tmp[i]].fi,TR::ad[tmp[i]].se) + lst + min(0ll,TR::mn[tmp[i]].se);
	}
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	// freopen("out.out","w",stdout);
#endif
	n = read(),m = read();
	int cnt = 0;
	for (int i = 1;i <= m;i++){
		int t = read();
		if (t == 1){
			int l = read(),r = read(),x = read(),y = read();
			ops[++cnt] = (OP){i,1,x,y};
			mvec[l].emplace_back(cnt);
			mvec[r + 1].emplace_back(-cnt);
			q1[++q1cnt] = cnt;
		}
		if (t == 2){
			int l = read(),r = read(),w = read();
			ops[++cnt] = (OP){i,2,w,0};
			mvec[l].emplace_back(cnt);
			mvec[r + 1].emplace_back(-cnt);
		}
		if (t == 3){
			int k = read(),p = read(),q = read();
			ops[++cnt] = (OP){i,3,q,0};
			qvec[k].emplace_back(cnt);
			ops[++cnt] = (OP){-i,3,p - 1,0};
			qvec[k].emplace_back(cnt);
			isqry[i] = 1;
		}
	}
	for (int i = 1;i <= n;i++){
		for (int p : mvec[i]){
			if (p > 0){
				if (ops[p].t == 1) TR::modify(1,1,m,ops[p].i,ops[p].a,ops[p].b);
				else TR::modify(1,1,m,ops[p].i,-ops[p].a,0);
			}else TR::modify(1,1,m,ops[-p].i,0,0);
		}
		for (int p : qvec[i]){
			ll v = query(abs(ops[p].i),ops[p].a);
			if (ops[p].i > 0) ans[ops[p].i] += v;
			else ans[-ops[p].i] -= v;
		}
	}
	for (int i = 1;i <= m;i++) if (isqry[i]) printf("%lld\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 18ms
memory: 9560kb

input:

4907 4910
2 763 3330 1
3 307 1 1
1 2262 3430 22699 89397
1 1915 4000 51541 67587
2 212 2990 9763
2 1086 2162 1
2 1813 4496 16760
1 51 2796 68005 99390
1 1267 1519 74236 66178
3 1768 23808 54314
2 900 4122 27758
3 3287 17350 28989
2 3277 4024 3633
2 444 4866 1
2 353 4219 1061
1 987 3141 99906 17320
2...

output:

0
0
2591529633
0
0
0
491951691
0
44476260
0
0
0
0
0
0
0
1027306281
16223963435
0
0
3868951467
0
2063600023
0
4731863910
1381987293
0
15111
149141295
12569956868
12112581141
167237028
0
4879847273
20212825331
2248857134
16041
0
5510807300
0
0
0
9052068012
12939443220
0
0
0
0
1146956917
0
0
0
38689514...

result:

wrong answer 2nd numbers differ - expected: '3032090730', found: '0'

Subtask #2:

score: 0
Runtime Error

Test #6:

score: 0
Runtime Error

input:

99999 99998
1 5026 18575 27178 90423
3 30623 1 1
3 76936 1 1
1 77021 95683 84664 24734
1 46085 74886 40512 11266
3 5048 8594 22468
1 53318 77721 97151 70784
1 70645 91192 37556 13013
1 56752 56940 91812 62887
1 7928 34576 87339 69404
3 74875 32807 100970
3 22338 17221 25771
3 21421 20602 57957
3 717...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #12:

score: 0
Runtime Error

input:

100000 99993
1 47773 70467 16065 1
2 52349 78446 2304
3 40821 1 1
1 40216 93069 78144 1
1 41089 43671 76025 1
2 35263 68629 31066
3 79881 13534 57327
3 5556 1 1
2 21962 38192 1
1 664 58116 9417 1
3 28089 6039 7989
2 88500 90302 9946
3 63215 49410 60770
2 11069 89527 57581
2 70303 97603 12363
1 3420 ...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #17:

score: 0
Runtime Error

input:

99999 99996
3 77889 1 10000000000
1 6316 86327 89644 386
3 9260 1 10000000000
2 2603 47234 69717
2 20260 73011 19290
2 62477 81233 26127
1 50140 68508 37004 98794
2 14449 22788 16063
1 43860 84932 50375 21777
1 67345 94584 28202 66610
2 661 68654 1
1 14411 94422 82738 61196
1 16563 94416 4920 38408
...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%