QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585883#5415. RopewayPonyHexTL 20ms7944kbC++202.8kb2024-09-23 22:39:582024-09-23 22:39:59

Judging History

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

  • [2024-09-23 22:39:59]
  • 评测
  • 测评结果:TL
  • 用时:20ms
  • 内存:7944kb
  • [2024-09-23 22:39:58]
  • 提交

answer

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define ll long long
#define double long double
#define lc u<<1
#define rc u<<1|1
#define X first
#define Y second
//#define int long long
const int N = 5e5 + 50;
const int M = 5e5 + 5;
const ll maxm = 1e18 + 5;
const ll mod = 998244353;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
//random_shuffle(id + 1, id + n + 1);
ll ksm(ll a, ll b);
ll gcd(ll a, ll b);

ll n, k, Q;
ll a[N];
string str;
ll dp[N] = { 0 };//表示在以第i个位置结尾的最小代价
ll ddp[N];

void solve()
{
	//感觉就是个dp,但是这n,q有点太大了点,
	//对于每个q都用n的复杂度跑,感觉会t
	//但是之前,我们已经获取了一部分,(在更改的元素之前的序列)
	//那部分,我们是可以接着用的,每次我们从那个地方开始,能优化一下
	//试试
	//怎么还有位置是要必须建,等等还有这种好事
	//为1的位置相当于把整个数列进行了划分
	//到单点修改导致的决策影响仅能影响到下一个一的位置
	//在往后的决策都直接加上前置的决策即可

	//写的一坨,思路比较纯实现还不好,单调队列能维护出n的复杂度求
	//先改一发试试

	priority_queue < pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > >q;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i];
	cin >> str; str = "1" + str; str = str + "1"; a[n + 1] = 0; a[0] = 0;
	q.push({ 0,0 }); dp[0] = 0;
	for (int i = 1; i <= n+1; i++) {
		while (q.size() && i - q.top().Y > k)q.pop();
		dp[i] = q.top().X + a[i];
		if (str[i] == '1') {
			while (q.size())q.pop();
		}
		q.push({ dp[i],i });
	}
	while (q.size())q.pop();
	cin >> Q;
	for (int i = 1; i <= Q; i++) {
		ll pos, val; cin >> pos >> val;
		//单点修改以后可怎么搞
		//总不能再跑完,试试,要不
		if (str[pos] == '1') {
			cout << dp[n + 1] + (-a[pos] + val) << endl; continue;
		}
		for (int ii = max(0ll, pos - k); ii < pos; ii++) {
			if (str[ii] == '1') {
				while (q.size())q.pop();
			}
			q.push({ dp[ii],ii });
		}
		q.push({ dp[pos] - a[pos] + val,pos });
		for (int ii = pos + 1; ii <= n + 1; ii++) {
			while (q.size() && ii - q.top().Y > k)q.pop();
			ddp[ii] = q.top().X + a[ii];
			if (str[ii] == '1') {
				while (q.size())q.pop();
			}
			q.push({ ddp[ii],ii });
		}
		while (q.size())q.pop();
		cout << ddp[n + 1] << endl;
	}

	return;
}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T = 1;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*PonyHex*/


ll ksm(ll a, ll b) {
	ll base = a;
	ll ans = 1;
	while (b) {
		if (b & 1)ans *= base % mod;
		ans %= mod;
		base *= base; base %= mod;
		b >>= 1;
	}
	return ans % mod;
}
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7944kb

input:

3
10 3
5 10 7 100 4 3 12 5 100 1
0001000010
2
2 3
6 15
5 6
1 1 1 1 1
00000
1
3 100
5 6
1 1 1 1 1
00100
1
3 100

output:

206
214
0
100

result:

ok 4 number(s): "206 214 0 100"

Test #2:

score: 0
Accepted
time: 4ms
memory: 7652kb

input:

500
19 6
285203460 203149294 175739375 211384407 323087820 336418462 114884618 61054702 243946442 19599175 51974474 285317523 222489944 26675167 300331960 1412281 324105264 33722550 169011266
1111111110110100011
18
3 127056246
5 100630226
14 301161052
2 331781882
5 218792226
2 190274295
12 49227476
...

output:

2472886431
2299111966
2796055445
2650202148
2417273966
2508694561
2285479513
2521569560
2521569560
2240907690
2577284958
2521569560
2766700195
2511807344
2521569560
2438434986
2669077215
2682112324
470735446
470735446
211705888
564509290
715543137
470735446
470735446
18
19
19
19
20
19
54
849950346
8...

result:

ok 5277 numbers

Test #3:

score: 0
Accepted
time: 20ms
memory: 7660kb

input:

50
183 160
22617237 21369258 39718669 4582413 28629717 25947766 1690897 19844235 35568283 42909820 21829213 70588436 8472484 53107624 21547259 11440081 6630789 5896457 19770793 30204510 29796593 27689811 39350369 21646987 36362667 38164292 13428410 54681069 24526477 58941286 70890011 43730474 388615...

output:

5303746210
5262479222
5346682277
5299354906
5290045662
5350552810
5343191051
5268759163
5299354906
5340227887
5299354906
5253956732
5289945955
5230918240
5287812187
5299354906
5299354906
5273800386
5299354906
5299354906
5353471727
5283662384
5230330060
5319166005
5338060400
5304825609
5268929476
526...

result:

ok 9541 numbers

Test #4:

score: -100
Time Limit Exceeded

input:

3
500000 891
806445768 895003544 461699845 184479965 853541910 593542573 667984604 465354540 303586741 243665567 285056069 294245042 675066412 456713460 215929340 756894934 773828574 317143965 451366539 891390118 436168373 633752416 78781758 298770626 35280548 226923750 96421159 523108871 265102517 ...

output:

5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
5202946193
520...

result: