-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_1_Consecutive_Cuts_-_Chapter_1.cpp
More file actions
191 lines (181 loc) · 3.78 KB
/
A_1_Consecutive_Cuts_-_Chapter_1.cpp
File metadata and controls
191 lines (181 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// ⋱C⋱r⋱i⋱s⋱t⋱i⋱a⋱n⋱o⋱⋱⋱R⋱o⋱n⋱a⋱l⋱d⋱o⋱.⋱.⋱.⋱.⋱.⋱.⋱G⋱O⋱A⋱T
// P⋱a⋱r⋱t⋱h⋱i⋱v⋱⋱⋱S⋱a⋱r⋱k⋱a⋱r
// ⋱
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <climits>
#include <queue>
using namespace std;
const int inf = 1000000000;
#define mod 1000000007
#define mod1 998244353
#define maxn 5000000
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, n) for (lli i = a; i < n; i++)
#define rrep(i, n, a) for (lli i = n; i >= a; i--)
#define pie acos(-1.0)
typedef long long ll;
typedef long double ld;
typedef long long int lli;
typedef unsigned long long int llu;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pl;
typedef vector<pl> vp;
#define cin(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define store(b, n) \
for (int i = 0; i < n; i++) \
b[i] = a[i];
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define line cout << endl
ll a[5000100];
ll b[5000100];
ll vis[200005];
vll adj[400005];
vll fact(2000009);
vector<bool> isprime;
vll primes;
int dx[] = {1, 0, 0, -1}; // Four Directions
int dy[] = {0, -1, 1, 0}; // Four directions
void sieve(ll n)
{
if ((ll)isprime.size() >= n + 1)
return;
isprime.assign(n + 1, true);
isprime[0] = isprime[1] = false;
ll sqrtn = (ll)(sqrt(n * 1.) + .5);
for (ll i = 2; i <= sqrtn; i++)
if (isprime[i])
{
for (ll j = i * i; j <= n; j += i)
isprime[j] = false;
}
primes.clear();
for (ll i = 2; i <= n; i++)
if (isprime[i])
primes.push_back(i);
}
void factorial()
{
fact[0] = 1;
fact[1] = 1;
for (ll i = 2; i <= 2000009; i++)
{
fact[i] = (i * fact[i - 1]) % mod;
}
}
ll modexpo(ll x, ll y)
{
ll ans = 1;
x = (x % mod);
while (y > 0)
{
if (y & 1)
ans = ((ans % mod) * (x % mod)) % mod;
x = ((x % mod) * (x % mod)) % mod;
y >>= 1;
}
return ans % mod;
}
ll inv_mod(ll x)
{
ll a = 1, p = x, n = 1000000005;
while (n)
{
if (n & 1)
a = (a * p) % mod;
p = (p * p) % mod;
n >>= 1;
}
return a;
}
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
if (a == 0)
return b;
else
return gcd(b, a % b);
}
ll n = 0, k, m = 0;
void solve()
{
ll T;
cin >> T;
rep(I, 1, T + 1)
{
ll i, j;
cout << "Case #" << I << ": ";
cin>>n>>k;
vll v(n),v1(n);
map<ll,ll>mp1,mp2;
rep(i,0,n){
cin>>v[i];
mp1[v[i]]=i;
}
rep(i,0,n){
cin>>v1[i];
mp2[v1[i]]=i;
}
if(k==0 && v!=v1){
no;
continue;
}
bool f=1;
ll val= mp2[v[0]]-mp1[v[0]];
for(i = 1; i < n; i++){
if(mp2[v[i]] != (i + val)%n){
f = 0;
break;
}
}
if(!f){
no;
}
else{
if(n == 2){
if(val % 2 == k % 2){
yes;
}
else{
no;
}
}
else{
if(k == 1 and val == 0){
no;
}
else{
yes;
}
}
}
}
}
int main()
{
cin.tie(nullptr);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
// freopen("inpi.txt", "r", stdin);
// freopen("outpi.txt", "w", stdout);
// int t;
// cin >> t;
// while (t--)
solve();
return 0;
}