Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhu23 authored Jul 26, 2023
1 parent ba9e440 commit f3e4538
Show file tree
Hide file tree
Showing 7 changed files with 841 additions and 0 deletions.
12 changes: 12 additions & 0 deletions codeforces/div 3/888/A_Escalator_Conversations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def solve():
n, m, k, h = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for x in a:
if x % k == h % k and 0 < abs(h - x) <= (m - 1) * k:
cnt += 1
print(cnt)

t = int(input())
for i in range(t):
solve()
13 changes: 13 additions & 0 deletions codeforces/div 3/888/B_Parity_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

def solve():
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
ans = True
for i in range(n):
ans &= a[i] % 2 == b[i] % 2
print("YES" if ans else "NO")

t = int(input())
for i in range(t):
solve()
24 changes: 24 additions & 0 deletions codeforces/div 3/888/C_Tiles_Comeback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
b, c = [0 for i in range(n)], [0 for i in range(n)]
b[0], c[-1] = 1, 1
for i in range(1, n):
b[i] = b[i - 1]
if a[i] == a[0]: b[i] += 1
for i in range(n - 2, -1, -1):
c[i] = c[i + 1]
if a[i] == a[-1]: c[i] += 1
ans = False
for i in range(n - 1):
if b[i] >= k:
ans = c[i + 1] >= k
break
if a[0] == a[-1]: ans = b[-1] >= k
if ans: print("YES")
else: print("NO")

t = int(input())

for i in range(t):
solve()
183 changes: 183 additions & 0 deletions codeforces/div 3/888/D_Prefix_Permutation_Sums.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* Author: Andy Zhu
* @date 2023-07-25 16:43:40
* @version 1.0.0
*/

// optimize
#pragma GCC optimize(2)

//include
#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// template <typename T>
// using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// template <typename T>
// using ordered_multiset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;

// pairs
#define fir first
#define sec second

// segment tree
#define lc (rt << 1)
#define rc (rt << 1 | 1)

// STL Data Structures
#define eb emplace_back
#define ef emplace_front
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define ins insert
#define lb lower_bound
#define ub upper_bound

// random
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define random(a, b) rng() % (b - a + 1) + a

// Data Structure Shorten
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
template <typename T> using vec = vector<T>;
template <typename T> using us = unordered_set<T>;
template <typename T> using os = set<T>;
template <typename T> using ms = multiset<T>;
template <typename T1, typename T2> using um = unordered_map<T1, T2>;
template <typename T1, typename T2> using om = map<T1, T2>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using pqg = priority_queue<T, vector<T>, greater<T> >;
using vi = vector<int>;
using vpii = vector<pair<int, int> >;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long> >;
using vb = vector<bool>;

// common functions

namespace comfun {
template <typename T1, typename T2> inline void ckmax(T1& u, T2 v) { u = max(u, v); }
template <typename T1, typename T2> inline void ckmin(T1& u, T2 v) { u = min(u, v); }
template <typename T> inline T lowbit(T x){return x & (- x);}
template <typename T> inline T gcd(T a, T b){if(b == 0) return a; return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b){return a / gcd(a, b) * b;}
template <typename T1, typename T2> inline T1 fp(T1 a, T2 b) {T1 c = 1;while(b) {if(b & 1) c *= a;b >>= 1;a = a * a;}return c;}
template <typename T1, typename T2, typename T3> inline T1 fp(T1 a, T2 b, T3 mod)
{T1 c = 1;while(b) {if(b & 1) c = c * a % mod;b >>= 1;a = a * a % mod;}return c;}
template <typename T> inline bool is_prime(T x){if(x == 1) return false; for(T i = 2; i * i <= x;i++) if(x % i == 0) return false; return true;}
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

namespace fast_io {
int read() {int x = 0, f = 0; char ch = getchar();while (!isdigit(ch)) f |= ch == '-', ch = getchar();while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();return f ? -x : x;}
long long readLL() {long long x = 0, f = 0; char ch = getchar();while (!isdigit(ch)) f |= ch == '-', ch = getchar();while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();return f ? -x : x;}
template<typename T> T read(T& x) {x = 0; int f = 0; char ch = getchar();while (!isdigit(ch)) f |= ch == '-', ch = getchar();while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();x = f ? -x : x; return x;}
template<typename T> void print(T x) {if (x < 0) putchar('-'), x = -x;if (x >= 10) print(x / 10);putchar(x % 10 + '0');}
template<typename T> void print(T x, char let) {print(x), putchar(let);}
}

// using namespaces
using namespace comfun;
using namespace fast_io;

// common variables
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int dir[8][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}, {-1, 1}, {1, -1}, {-1, -1}, {1, 1}};
const unordered_set<char> vowel = {'a', 'e', 'i', 'o', 'u'};

//------------------- start of initialize --------------------
// initialize for all cases
inline void init1(){

}

//------------------- end of initialize --------------------

//--------------------- start of program ---------------------

const int N = 2e5 + 5;
int n, a[N];
set<int> vis;

inline void solve(){
read(n);
vis.clear();
for(int i = 1;i<n;++i) read(a[i]), vis.ins(i);
vis.ins(n);
int mx;
for(int i = 1;i<n;++i) {
if(!vis.count(a[i] - a[i - 1])) mx = a[i] - a[i - 1];
vis.erase(a[i] - a[i - 1]);
}
if(vis.size() == 1) {
puts("YES");
return;
}
if(vis.size() != 2) {
puts("NO");
return;
}
puts(*vis.begin() + *vis.rbegin() == mx ? "YES" : "NO");
}


//--------------------- end of program ---------------------


#define doCase 1
#define config LOCAL
// #define kickstart
#define unsync 0

inline void setIO() {
#if config
// configuration here
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
#if unsync
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
}

signed main(){
setIO();
init1();
srand(time(0));
#if doCase
int t; t = read();
for(int i = 1;i<=t;i++) {
#ifdef kickstart
printf("Case #%d: ", i);
#endif
solve();
}
#else
solve();
#endif
string jack = "Jack is always within you";
return 0;
}


/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Loading

0 comments on commit f3e4538

Please sign in to comment.