Submission #72703130


Source Code Expand

#include <bits/stdc++.h>
const int maxn=5e5+5;
using namespace std;
int q,n;
int a[maxn];
int sum[maxn];
int lowbit(int x)
{
	return x&-x;
}
void upd(int x,int y)
{
	for (int i=x;i<=n;i+=lowbit(i))
		sum[i]+=y;
}
int qry(int x)
{
	int ret=0;
	for (int i=x;i;i-=lowbit(i))
		ret+=sum[i];
	return ret;
}
int main()
{
	cin >> n >> q;
	for (int i=1;i<=n;i++) cin >> a[i],upd(i,a[i]);
	for (int i=1;i<=q;i++)
	{
		int ch;
		cin >> ch;
		if (ch==1)
		{
			int x;
			cin >> x;
			int val1=a[x];
			int val2=a[x+1];
			upd(x,-val1);
			upd(x,val2);
			upd(x+1,val1);
			upd(x+1,-val2);
			swap(a[x],a[x+1]);
		}
		else
		{
			int l,r;
			cin >> l >> r;
			cout << qry(r)-qry(l-1) << endl;
		}
	}
	return 0;
}

Submission Info

Submission Time
Task D - Swap and Range Sum
User ChaoticZao
Language C++23 (GCC 15.2.0)
Score 400
Code Size 750 Byte
Status AC
Exec Time 405 ms
Memory 7668 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 29
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3408 KiB
00_sample_01.txt AC 1 ms 3472 KiB
01_random_00.txt AC 405 ms 6736 KiB
01_random_01.txt AC 396 ms 6412 KiB
01_random_02.txt AC 363 ms 5720 KiB
01_random_03.txt AC 323 ms 5128 KiB
01_random_04.txt AC 311 ms 5072 KiB
01_random_05.txt AC 283 ms 5052 KiB
01_random_06.txt AC 254 ms 4900 KiB
01_random_07.txt AC 244 ms 5052 KiB
01_random_08.txt AC 213 ms 5072 KiB
01_random_09.txt AC 186 ms 4960 KiB
01_random_10.txt AC 152 ms 5008 KiB
01_random_11.txt AC 397 ms 7304 KiB
01_random_12.txt AC 381 ms 6932 KiB
01_random_13.txt AC 355 ms 6392 KiB
01_random_14.txt AC 330 ms 5596 KiB
01_random_15.txt AC 308 ms 5300 KiB
01_random_16.txt AC 286 ms 5200 KiB
01_random_17.txt AC 261 ms 5244 KiB
01_random_18.txt AC 237 ms 5048 KiB
01_random_19.txt AC 214 ms 5244 KiB
01_random_20.txt AC 189 ms 4900 KiB
01_random_21.txt AC 163 ms 5008 KiB
01_random_22.txt AC 283 ms 5088 KiB
01_random_23.txt AC 287 ms 5076 KiB
02_handmade_00.txt AC 1 ms 3576 KiB
02_handmade_01.txt AC 1 ms 3492 KiB
02_handmade_02.txt AC 379 ms 7668 KiB