QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#335645#4918. 染色bear01310 17ms99712kbC++147.2kb2024-02-23 18:09:412024-02-23 18:09:42

Judging History

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

  • [2024-02-23 18:09:42]
  • 评测
  • 测评结果:0
  • 用时:17ms
  • 内存:99712kb
  • [2024-02-23 18:09:41]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int Mod = 1e9 + 7;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, ll p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 111;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN], inv[fN];
void initfact(int n){
	pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
	invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
	for(int i = 1; i <= n; ++i) inv[i] = mul(invfact[i], fact[i-1]);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(int &a, int b){ (b>a) ? (a=b) : 0; }
inline void chmin(int &a, int b){ (b<a) ? (a=b) : 0; }

int n, m;

struct myheap{
	priority_queue< int, vi, greater<int> > pq0, pq1;
	myheap(){}
	inline void ins(int x){ pq0.push(x); }
	inline void del(int x){ pq1.push(x); }
	inline int top(){
		while(!pq0.empty() && !pq1.empty() && pq0.top() == pq1.top()) pq0.pop(), pq1.pop();
		return pq0.empty() ? inf : pq0.top();
	}
	void trav(){
		vi tmp;
		cout << "{";
		while(!pq0.empty()) tmp.push_back(pq0.top()), cout << pq0.top() << ", ", pq0.pop();
		for(auto x : tmp) pq0.push(x);
		tmp.clear();
		cout << "} - {";
		while(!pq1.empty()) tmp.push_back(pq1.top()), cout << pq1.top() << ", ", pq1.pop();
		for(auto x : tmp) pq1.push(x);
		tmp.clear();
		cout << "}";
	}
};

myheap has[1200120];
int mn[1200120], mncnt[1200120]; ull sum[1200120], mntag[1200120], alltag[1200120];

void pushup(int l, int r, int u){
	mn[u] = min({has[u].top(), mn[u+u], mn[u+u+1]});
	if(mn[u] == has[u].top()) mncnt[u] = r - l + 1;
	else mncnt[u] = (mn[u+u] == mn[u] ? mncnt[u+u] : 0) + (mn[u+u+1] == mn[u] ? mncnt[u+u+1] : 0);
	sum[u] = sum[u+u] + sum[u+u+1];
}

void pushalltag(int l, int r, int u, ull v){ sum[u] += v * (r-l+1), alltag[u] += v; }
void pushmntag(int l, int r, int u, ull v){
	//cout << "pushtag " << l << " " << r << " " << u << " " << v << endl;
	(mn[u] == has[u].top()) ? pushalltag(l, r, u, v) : (sum[u] += v * mncnt[u], mntag[u] += v, void());
}
void pushdown(int l, int r, int u){
	int mid = (l+r) >> 1;
	if(mn[u+u] == mn[u]) pushmntag(l, mid, u+u, mntag[u]);
	if(mn[u+u+1] == mn[u]) pushmntag(mid+1, r, u+u+1, mntag[u]);
	pushalltag(l, mid, u+u, alltag[u]), pushalltag(mid+1, r, u+u+1, alltag[u]);
	mntag[u] = alltag[u] = 0;
}

void build(int l, int r, int k){
	if(l == r) return mn[k] = inf, mncnt[k] = 1, void();
	int mid = (l+r) >> 1;
	build(l, mid, k+k), build(mid+1, r, k+k+1);
	pushup(l, r, k);
}

void col(int tp, int tl, int tr, int x, int l, int r, int k){
	//cout << "col " << tp << " " << tl << " " << tr << " " << x << " " << l << " " << r << " " << k << endl;
	if(tl > r || l > tr) return ;
	pushdown(l, r, k);
	if(tl <= l && r <= tr) return (tp ? has[k].del(x) : has[k].ins(x)), pushup(l, r, k);
	int mid = (l+r) >> 1;
	col(tp, tl, tr, x, l, mid, k+k), col(tp, tl, tr, x, mid+1, r, k+k+1);
	pushup(l, r, k);
}

int qrymn(int tl, int tr, int l, int r, int k){
	if(tl > r || l > tr) return inf;
	if(tl <= l && r <= tr) return mn[k];
	//pushdown(l, r, k); // 没必要吧
	int mid = (l+r) >> 1;
	return min({qrymn(tl, tr, l, mid, k+k), qrymn(tl, tr, mid+1, r, k+k+1), has[k].top()});
}

void updall(int tl, int tr, ull v, int l, int r, int k){
	if(tl > r || l > tr) return ;
	if(tl <= l && r <= tr) return pushalltag(l, r, k, v);
	pushdown(l, r, k);
	int mid = (l+r) >> 1;
	updall(tl, tr, v, l, mid, k+k), updall(tl, tr, v, mid+1, r, k+k+1);
	pushup(l, r, k);
}
void updmn(int tl, int tr, int curmn, ull v, int l, int r, int k){
	//cout << "updmn " << tl << " " << tr << " " << curmn << " " << v << endl;
	if(tl > r || l > tr || mn[k] > curmn) return ;
	if(tl <= l && r <= tr) return pushmntag(l, r, k, v);
	pushdown(l, r, k);
	int mid = (l+r) >> 1;
	if(has[k].top() == curmn){
		updall(tl, tr, v, l, r, k);
	} else {
		updmn(tl, tr, curmn, v, l, mid, k+k), updmn(tl, tr, curmn, v, mid+1, r, k+k+1);
	}
	pushup(l, r, k);
}

ull qrysum(int tl, int tr, int l, int r, int k){
	if(tl > r || l > tr) return 0;
	if(tl <= l && r <= tr) return sum[k];
	pushdown(l, r, k);
	int mid = (l+r) >> 1;
	return qrysum(tl, tr, l, mid, k+k) + qrysum(tl, tr, mid+1, r, k+k+1);
}

void trav(int l, int r, int k){
	//cout << " | " << l << " " << r << " " << k << ": " << mn[k] << " " << mncnt[k] << "  " << sum[k] << " " << mntag[k] << " " << alltag[k] << ": ";
	has[k].trav();
	//cout << "\n";
	if(l < r){
		int mid = (l+r) >> 1;
		trav(l, mid, k+k), trav(mid+1, r, k+k+1);
	}
}

set<pii> st[300300];

int main(){
	//freopen("ex_paint2.in", "r", stdin);
	//freopen("paint.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;

	build(0, n-1, 1);
	rep(i, m+1) col(0, 0, n-1, i, 0, n-1, 1), st[i].insert(make_pair(0, n-1));

	while(m--){
		//cout << "------------------" << m << "-------------------" << endl;
		int tp;
		cin >> tp;
		if(tp == 2){
			int l, r, x;
			cin >> l >> r >> x;
			--l, --r, --x;
			auto it = st[x].lower_bound(make_pair(l, -1));
			if(it != st[x].begin() && prev(it)->second >= l) --it, l = it->first;
			while(it != st[x].end() && it->first <= r){
				chmax(r, it->second);
				col(1, it->first, it->second, x, 0, n-1, 1);
				it = st[x].erase(it);
			}
			st[x].insert(make_pair(l, r));
			col(0, l, r, x, 0, n-1, 1);
		} else if(tp == 1){
			int l, r, x;
			cin >> l >> r >> x;
			--l, --r, --x;
			auto it = st[x].lower_bound(make_pair(l, -1));
			if(it != st[x].begin() && prev(it)->second >= l) --it;
			vector<pii> tmp;
			while(it != st[x].end() && it->first <= r){
				col(1, it->first, it->second, x, 0, n-1, 1);
				//cout << it->first << " " << it->second << "  " << l << " " << r << endl;
				if(it->first < l) tmp.push_back(make_pair(it->first, l-1));
				if(it->second > r) tmp.push_back(make_pair(r+1, it->second));
				it = st[x].erase(it);
			}
			for(auto p : tmp) col(0, p.first, p.second, x, 0, n-1, 1), st[x].insert(p);
		} else if(tp == 3){
			int l, r; ull v;
			cin >> l >> r >> v;
			--l, --r;
			int curmn = qrymn(l, r, 0, n-1, 1);
			//cout << " " << curmn << endl;
			updmn(l, r, curmn, v, 0, n-1, 1);
		} else {
			int l, r;
			cin >> l >> r;
			--l, --r;
			cout << qrysum(l, r, 0, n-1, 1) << "\n";
		}
		//trav(0, n-1, 1);
		//cout << "fin." << endl;
	}

	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 13ms
memory: 99712kb

input:

1000 1000
3 722 914 2141556875752121755
3 323 347 6433743606947304931
2 142 206 439
2 117 840 195
2 127 502 56
3 168 707 15142638115094015116
4 190 257
2 88 976 475
1 319 867 351
1 682 889 409
2 406 446 196
3 28 35 4899387534800369959
2 291 546 150
1 528 617 128
1 58 122 251
2 381 400 276
4 510 958
...

output:

15128467772367689008
17361914246216994339
5483226026482017320
3033562207293358603
2081407883485577238
7431958406282818646
4664359672511637691
8517692808398202534
17884251128335023776
3389445997760709607
15161173652136060523
17246899135664170339
16659472119973467421
5618344994614112283
92650283427734...

result:

ok 288 tokens

Test #2:

score: -10
Wrong Answer
time: 17ms
memory: 99684kb

input:

1000 1000
1 538 681 44
2 112 540 10
1 160 191 28
1 276 867 1
4 118 419
4 62 209
1 575 884 37
1 783 895 45
4 342 410
2 545 870 16
1 273 501 11
3 258 352 13270291835335737625
3 490 514 5208698592597571883
2 629 865 43
3 966 981 14431353048791951405
1 290 809 16
4 468 843
1 607 875 26
2 177 521 6
4 176...

output:

0
0
0
0
17504324151528657858
2987455658418197192
0
0
13815347553406398201
5603739312727078592
17885258495700927170
0
17017493826130588942
5600801614830233724
849737692109005723
14509475714445605346
17689625573786113686
16372053285051170686
7566556261498476947
4770359948078301544
15903364361457196198...

result:

wrong answer 4th words differ - expected: '1090256298972435763', found: '0'

Subtask #2:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

input:

300000 300000
1 237576 237663 1
3 16150 16208 9270412155482010138
2 175648 175692 1
4 190836 190849
4 199010 199097
1 73976 298801 1
3 89902 89939 6418828085116455990
3 55415 55461 12238963685511262676
3 119825 119875 8146944792877919309
3 135103 135158 218634681842812119
3 127261 127352 13291431184...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #31:

score: 0
Runtime Error

input:

300000 300000
1 85444 86076 59
1 41150 41411 71
1 278698 279414 45
1 238445 239202 56
1 29965 29984 49
1 282953 283272 37
1 34668 35653 86
2 198587 198744 28
1 270855 271611 58
1 2130 2965 773
1 161601 162298 937
1 50299 50435 36
1 100759 101198 64
1 120208 120543 84
1 295293 295732 34
1 112185 1129...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%