Submission #64309319
Source Code Expand
#include <bits/stdc++.h>
#define _F(x,y,z) for(int x=y;x<=z;x++)
#define F_(x,z,y) for(int x=z;x>=y;x--)
#define TF(x,y,z) for(int x=head[y],z;x;x=nex[x])
using namespace std;
typedef long long ll;
typedef double dou;
typedef const int ci;
typedef pair<int,int> pii;
ci maxn=2e6+10;
int n,a[maxn],pi[maxn],mp[maxn],t;
int main()
{
scanf("%d",&t);
while(t--)
{
ll ans=0;
scanf("%d",&n);
_F(i,1,2*n+10)
mp[i]=pi[i]=a[i]=0;
_F(i,1,2*n)
{
scanf("%d",&a[i]);
if(mp[a[i]])
pi[i]=mp[a[i]],pi[mp[a[i]]]=i;
else
mp[a[i]]=i;
}
_F(i,1,2*n)
{
if(a[i]==a[i-1]||a[i]==a[i+1]) continue;
if(a[i]<a[i-1])
{
if(abs(pi[i-1]-pi[i])<=1&&abs(pi[i-1]-i+1)>1)
ans++;
}
if(a[i]<a[i+1])
{
if(abs(pi[i+1]-pi[i])<=1&&abs(pi[i+1]-i-1)>1)
ans++;
}
}
printf("%lld\n",ans/2);
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Switch Seats |
| User |
adolphshi |
| Language |
C++ 20 (gcc 12.2) |
| Score |
400 |
| Code Size |
894 Byte |
| Status |
AC |
| Exec Time |
45 ms |
| Memory |
8572 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
Main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
Main.cpp:27:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 02_random_1_00.txt, 02_random_1_01.txt, 02_random_1_02.txt, 02_random_1_03.txt, 02_random_1_04.txt, 03_random_2_00.txt, 03_random_2_01.txt, 03_random_2_02.txt, 04_max_00.txt, 05_corner_00.txt, 05_corner_01.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3748 KiB |
| 01_small_00.txt |
AC |
26 ms |
3772 KiB |
| 01_small_01.txt |
AC |
26 ms |
3692 KiB |
| 01_small_02.txt |
AC |
27 ms |
3696 KiB |
| 01_small_03.txt |
AC |
27 ms |
3824 KiB |
| 01_small_04.txt |
AC |
26 ms |
3828 KiB |
| 01_small_05.txt |
AC |
26 ms |
3888 KiB |
| 01_small_06.txt |
AC |
26 ms |
3696 KiB |
| 02_random_1_00.txt |
AC |
45 ms |
8572 KiB |
| 02_random_1_01.txt |
AC |
44 ms |
8348 KiB |
| 02_random_1_02.txt |
AC |
45 ms |
8448 KiB |
| 02_random_1_03.txt |
AC |
44 ms |
8512 KiB |
| 02_random_1_04.txt |
AC |
45 ms |
8452 KiB |
| 03_random_2_00.txt |
AC |
44 ms |
8272 KiB |
| 03_random_2_01.txt |
AC |
44 ms |
8376 KiB |
| 03_random_2_02.txt |
AC |
43 ms |
8572 KiB |
| 04_max_00.txt |
AC |
26 ms |
8448 KiB |
| 05_corner_00.txt |
AC |
26 ms |
8452 KiB |
| 05_corner_01.txt |
AC |
27 ms |
8316 KiB |