# Codeforces Round #641 (Div. 2)

A. Orac and Factors
/*
* Author:  heyuhhh
* Created Time:  2020/5/12 20:36:40
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

void run() {
int n, k; cin >> n >> k;
int t;
for (int i = 2; i <= n; i++) {
if (n % i == 0) {
t = i; break;
}
}
--k; n += t;
n += 2 * k;
cout << n << '\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}

B. Orac and Models
/*
* Author:  heyuhhh
* Created Time:  2020/5/12 20:44:31
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

int n;
int a[N];

vector <int> d[N];

void init() {
for (int i = 1; i < N; i++) {
for (int j = i + i; j < N; j += i) {
d[j].emplace_back(i);
}
}
}

void run() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector <int> f(n + 1, 1);
for (int i = 2; i <= n; i++) {
for (auto it : d[i]) {
if (a[it] < a[i]) f[i] = max(f[i], f[it] + 1);
}
}
int ans = 0;
for (int i = 1; i <= n; i++) ans = max(ans, f[i]);
cout << ans << '\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
init();
int T; cin >> T; while (T--)
run();
return 0;
}

C. Orac and LCM
/*
* Author:  heyuhhh
* Created Time:  2020/5/12 20:51:42
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5, M = 2e5 + 5;

int n;
int a[N];
vector <int> v[M];

ll qpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}

void run() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
int x = a[i];
for (int j = 2; 1ll * j * j <= x; j++) {
if (x % j == 0) {
int cnt = 0;
while (x % j == 0) {
x /= j;
++cnt;
}
v[j].push_back(cnt);
}
}
if (x > 1) {
v[x].push_back(1);
}
}
for (int i = 1; i < M; i++) {
sort(all(v[i]));
}
ll ans = 1;
for (int i = 1; i < M; i++) {
if (sz(v[i]) <= n - 2) continue;
if (sz(v[i]) == n - 1) {
ans *= qpow(i, v[i][0]);
} else {
ans *= qpow(i, v[i][1]);
}
}
cout << ans << '\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}

D. Orac and Medians
/*
* Author:  heyuhhh
* Created Time:  2020/5/12 21:36:28
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

int n;
int a[N];

void run() {
int n, k; cin >> n >> k;
int cnt = 0;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
if (x > k) a[i] = 1;
else if (x < k) a[i] = -1;
else a[i] = 0;
if (a[i] == 0) ++cnt;
}
auto chk = [&] () {
if (cnt == n) return true;
if (cnt == 0) return false;
for (int i = 1; i < n; i++) {
if (a[i] >= 0 && a[i + 1] >= 0) return true;
}
for (int i = 1; i < n - 1; i++) {
if (a[i] >= 0 && a[i + 2] >= 0) return true;
}
return false;
};
if (chk()) cout << "yes" << '\n';
else cout << "no" << '\n';
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}

E. Orac and Game of Life
/*
* Author:  heyuhhh
* Created Time:  2020/5/12 23:56:30
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << std::endl; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) {
for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e3 + 5;
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};

int n, m, t;
char s[N][N];
int a[N][N], dis[N][N];
bool vis[N][N];

void run() {
cin >> n >> m >> t;
for (int i = 1; i <= n; i++) {
cin >> (s[i] + 1);
for (int j = 1; j <= m; j++) {
a[i][j] = (s[i][j] - '0');
}
}
auto ok = [&] (int nx, int ny) {
return nx >= 1 && nx <= n && ny >= 1 && ny <= m;
};
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (!vis[i][j]) {
for (int k = 0; k < 4; k++) {
int x = i + dx[k], y = j + dy[k];
if (ok(x, y) && a[x][y] == a[i][j]) {
vis[i][j] = true;
}
}
}
}
}
memset(dis, INF, sizeof(dis));
queue <pii> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (vis[i][j]) {
q.push(MP(i, j));
dis[i][j] = 0;
}
}
}
while (!q.empty()) {
pii cur = q.front(); q.pop();
int x = cur.fi, y = cur.se;
auto ok = [&] (int nx, int ny) {
return nx >= 1 && nx <= n && ny >= 1 && ny <= m && !vis[nx][ny] && dis[nx][ny] > dis[x][y] + 1;
};
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (ok(nx, ny)) {
dis[nx][ny] = dis[x][y] + 1;
vis[nx][ny] = true;
q.push(MP(nx, ny));
}
}
}
while (t--) {
int i, j; ll p;
cin >> i >> j >> p;
if (p <= dis[i][j] || dis[i][j] == INF) {
cout << a[i][j] << '\n';
} else {
int r = (p - dis[i][j]) % 2;
cout << (a[i][j] ^ r) << '\n';
}
}
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}

posted @ 2020-05-13 10:52  heyuhhh  阅读(388)  评论(0编辑  收藏  举报