Задача А. Мельник Софія
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000000000000;
const int N = 100000+10;
const int M = 100;
const int N2 = 100+5;
const int N3 = 1000+5;
const int N4 = 10000+5;
const int N5 = 100000+5;
const int N6 = 1000000+5;
const int N7 = 10000000+5;
const string st2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string s1 = "abcdefghijklmnopqrstuvwxyz";
#define mod % MOD
#define filesio(x) freopen(x ".in", "r", stdin); freopen(x ".out", "w", stdout)
#define filesds(x) freopen(x ".dat", "r", stdin); freopen(x ".sol", "w", stdout)
#define filestt(x) freopen(x ".txt", "r", stdin); freopen(x ".txt", "w", stdout)
#define filestxt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ms(x, y) memset(x, sizeof(x), y)
#define sqr(a) ((a) * (a))
#define ld long double
#define outld(l) cout.precision(l);cout << fixed
#define s second
#define ll long long
#define f first
#define mp make_pair
#define y1 dbfuebfwkmjjzdbhqfja
#define time zdfheajbrkjasghduw
#define ull unsigned long long
#define randomize srand(time(NULL))
#define next ifhiuebf
#define last dkbffjrb
#define pb push_back
#define left second
#define pii pair<ll,ll>
ll a, b;
ll kol(ll p)
{
ll d=p*b+a,ans=0,res=-1,f=0;
ll dd=d;
while (dd>0)
{
f++;
dd/=10;
}
for (ll i=15; i>=1; i--)
{
ll pp=0;
for (int j=1; j<=i; j++)
pp=pp*10+9;
if (pp<d)
{
res=(pp-a)/b;
if (res==p) {res=-1; break;}
ans+=kol(res);
break;
}
}
ans+=(p-res)*f;
return ans;
}
void jelly(ll r, ll k)
{
ll p=0,g=r,t=0;
while (g>0)
{
t++;
g/=10;
}
while (r>0)
{
p++;
if (t-p+1==k) {cout<<r%10<<endl; exit(0);}
r/=10;
}
cout<<-1<<endl;
exit(0);
}
int main()
{
#ifdef LOCAL
filestxt;
#else
sync;
#endif // LOCAL
ll n, k;
cin>>a>>b>>n>>k;
ll f=0;
ll gf=k;
for (ll i=0; i<=n; i++)
{
ll l=a+i*b;
ll r=l,t=0;
while (l>0)
{
f++;
if (f>=10000000) break;
t++;
l/=10;
}
if (f>=10000000) break;
if (k<=t)
{
ll p=0;
while (r>0)
{
f++;
if (f>=10000000) break;
p++;
if (t-p+1==k) {cout<<r%10<<endl; return 0;}
r/=10;
}
} else k-=t;
}
ll l=1;
ll r=n;
k=gf;
while (r-l>1)
{
ll mid=(l+r)/2;
ll ansres=kol(mid);
if (kol(mid)<k) l=mid; else r=mid;
}
if (kol(r)<k) l=r;
k-=kol(l);
jelly(a+(l+1)*b,k);
}
Задача В. Бушовський Олександр
v=int(input())
n=int(input())
l=[0,31,28+v,31,30,31,30,31,31,30,31,30,30,31]
f,z=0,0
for _ in range(n):
d,m=map(int,input().strip().split('/'))
dd=(sum(l[:m])+d)%5
if dd==1: f+=1000
elif dd==0: z+=3
elif dd==2: f+=5000
else: f+=3000
print(f,z)
Задача С. Бушовський Олександр
from decimal import *
getcontext().prec=28
n=int(input())
l=[]
ans=0
s=set()
for _ in range(n):
a,b=map(int,input().split())
#ans+=find(a, b)
ab=Decimal(a)/Decimal(b)
if not ab in s: ans+=1; s|={ab}
print(ans)
Задача D. Ципко Антон
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
ll MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#ifndef LOCAL
#define endl "\n"
#endif
#ifndef LONG_LONG_MAX
#define LONG_LONG_MAX LLONG_MAX
#endif
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define filesdatsol(x) _read(x ".DAT"); _write(x ".SOL")
#define output _write("output.txt")
#define input _read("input.txt")
#define prev time_prev
#define remove tipa_remove
#define next tipa_next
#define mod % MOD
#define y1 hello_world
unsigned char ccc;
bool _minus = false;
template<typename T>
inline T sqr(T t) {
return (t * t);
}
inline void read(ll &n) {
n = 0;
_minus = false;
while (true) {
ccc = getchar();
if (ccc == ' ' || ccc == '\n')
break;
if (ccc == '-') {
_minus = true;
continue;
}
n = n * 10 + ccc - '0';
}
if (_minus)
n *= -1;
}
inline void read(int &n) {
n = 0;
_minus = false;
while (true) {
ccc = getchar();
if (ccc == ' ' || ccc == '\n')
break;
if (ccc == '-') {
_minus = true;
continue;
}
n = n * 10 + ccc - '0';
}
if (_minus)
n *= -1;
}
char wwww[19];
int kkkk;
inline void write(ll y) {
long long x = y;
kkkk = 0;
if (x < 0) {
putchar('-');
x *= -1;
}
if (!x)
++kkkk, wwww[kkkk] = '0';
else
while (x) {
++kkkk;
wwww[kkkk] = char(x % 10 + '0');
x /= 10;
}
for (int i = kkkk; i >= 1; --i)
putchar(wwww[i]);
}
#ifdef LOCAL
#define DEBUG
#endif
#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif
const int MAX = 1e3;
char ar[MAX][MAX];
int dp[4][MAX][MAX];
int l;
vector<int> vec[4000];
void build(int v, int l, int r, vector<int> &ar) {
vec[v].clear();
if (l == r) {
vec[v].push_back(ar[l]);
return;
}
int x = (l + r) >> 1;
build(v << 1, l, x, ar);
build(v << 1 | 1, x + 1, r, ar);
vec[v].reserve(r - l + 1);
vec[v].resize(r - l + 1);
merge(vec[v << 1].begin(), vec[v << 1].end(), vec[v << 1 | 1].begin(),
vec[v << 1 | 1].end(), vec[v].begin());
}
int get(int v, int tl, int tr, int l, int r, int val) {
if (l <= tl && tr <= r) {
l = 0, r = (int) vec[v].size() - 1;
int x;
if (vec[v].back() <= val)
return (int) vec[v].size();
while (l < r) {
x = (l + r) >> 1;
if (vec[v][x] <= val) {
l = x + 1;
} else {
r = x;
}
}
return l;
}
if (tr < l || r < tl)
return 0;
int x = (tl + tr) >> 1;
return get(v << 1, tl, x, l, r, val) + get(v << 1 | 1, x + 1, tr, l, r, val);
}
int solve(vector<ii> v) {
int ans = 0;
int i, j;
vector<int> e;
for (int j = 0; j < (int) v.size(); j++) {
e.push_back(-(v[j].second - j));
v[j].second -= j;
}
build(1, 0, (int) e.size() - 1, e);
int w;
int g = 0;
for (i = 0; i < (int) v.size(); i++) {
w = min(v[i].first + i - 1, (int) v.size() - 1);
if(i + l > w)
continue;
ans += get(1, 0, (int) e.size() - 1, i + l, w, i - 1);
}
//cout << "$ " << ans << " " << g << endl;
return ans;
}
int main() {
sync;
srand(time(NULL));
cout.precision(10);
cout << fixed;
#ifdef LOCAL
input;
#else
#endif
int n, m, l;
read(n);
read(m);
read(l);
::l = l / 4;
if(l % 4)
::l++;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
ar[i][j] = getchar();
}
getchar();
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
dp[0][i][j] = (ar[i][j] == '#' ? 0 : 1 + (i == 0 ? 0 : dp[0][i - 1][j]));
dp[1][i][j] = (ar[i][j] == '#' ? 0 : 1 + (j == 0 ? 0 : dp[1][i][j - 1]));
}
}
for(int i = n - 1; i >= 0; i--) {
for(int j = m - 1; j >= 0; j--) {
dp[2][i][j] = (ar[i][j] == '#' ? 0 : 1 + (i == n - 1 ? 0 : dp[2][i + 1][j]));
dp[3][i][j] = (ar[i][j] == '#' ? 0 : 1 + (j == m - 1 ? 0 : dp[3][i][j + 1]));
}
}
ll ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(i == 0 || j == 0) {
vector<ii> v;
int x = i, y = j;
while(x < n && y < m) {
v.push_back(make_pair(min(dp[2][x][y], dp[3][x][y]), min(dp[0][x][y], dp[1][x][y])));
x++, y++;
}
ans += solve(v);
}
}
}
cout << ans << endl;
}
Задача Е. Ципко Антон
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;
ll MOD = 1e9 + 7;
const ld E = 1e-9;
#define null NULL
#define ms(x) memset(x, 0, sizeof(x))
#ifndef LOCAL
#define endl "\n"
#endif
#ifndef LONG_LONG_MAX
#define LONG_LONG_MAX LLONG_MAX
#endif
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _read(x) freopen(x, "r", stdin)
#define _write(x) freopen(x, "w", stdout)
#define files(x) _read(x ".in"); _write(x ".out")
#define filesdatsol(x) _read(x ".DAT"); _write(x ".SOL")
#define output _write("output.txt")
#define input _read("input.txt")
#define prev time_prev
#define remove tipa_remove
#define next tipa_next
#define mod % MOD
#define y1 hello_world
unsigned char ccc;
bool _minus = false;
template<typename T>
inline T sqr(T t) {
return (t * t);
}
inline void read(ll &n) {
n = 0;
_minus = false;
while (true) {
ccc = getchar();
if (ccc == ' ' || ccc == '\n')
break;
if (ccc == '-') {
_minus = true;
continue;
}
n = n * 10 + ccc - '0';
}
if (_minus)
n *= -1;
}
inline void read(int &n) {
n = 0;
_minus = false;
while (true) {
ccc = getchar();
if (ccc == ' ' || ccc == '\n')
break;
if (ccc == '-') {
_minus = true;
continue;
}
n = n * 10 + ccc - '0';
}
if (_minus)
n *= -1;
}
char wwww[19];
int kkkk;
inline void write(ll y) {
long long x = y;
kkkk = 0;
if (x < 0) {
putchar('-');
x *= -1;
}
if (!x)
++kkkk, wwww[kkkk] = '0';
else
while (x) {
++kkkk;
wwww[kkkk] = char(x % 10 + '0');
x /= 10;
}
for (int i = kkkk; i >= 1; --i)
putchar(wwww[i]);
}
#ifdef LOCAL
#define DEBUG
#endif
#ifdef DEBUG
#define dbg if(1)
#else
#define dbg if(0)
#endif
const int MAX = 3e5 + 1;
int n, m, k;
int color[MAX];
vector<int> vec[MAX], v1[MAX], v2[MAX];
int S;
bool big[MAX];
unordered_map<int, int> M[MAX];
int get(int pos, int col) {
if (big[pos]) {
return M[pos][col];
}
int ans = 0;
for (int a : vec[pos]) {
if (color[a] == col) {
ans++;
}
}
return ans;
}
void change(int pos, int col) {
for (int a : v2[pos]) {
if(!--M[a][color[pos]]){
M[a].erase(color[pos]);
}
M[a][col]++;
}
color[pos] = col;
}
int main() {
sync;
srand(time(NULL));
cout.precision(10);
cout << fixed;
#ifdef LOCAL
input;
#else
#endif
read(n);
read(m);
read(k);
for(int i = 1; i <= n; i++) {
read(color[i]);
}
vec[1].push_back(2);
vec[2].push_back(1);
for(int i = 3; i <= n; i++) {
int a;
read(a);
vec[a].push_back(i);
vec[i].push_back(a);
}
S = 550; // TODO
for(int i = 1; i <= n; i++) {
big[i] = (int) vec[i].size() >= S;
}
for(int i = 1; i <= n; i++) {
for(int a : vec[i]) {
if(big[a]) {
v2[i].push_back(a);
} else {
v1[i].push_back(a);
}
}
}
for(int i = 1; i <= n; i++) {
if(big[i]) {
for(int a : vec[i]) {
M[i][color[a]]++;
}
}
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
ans += get(i, color[i]);
}
ans /= 2;
while(m--) {
int pos, col;
read(pos);
read(col);
ans -= get(pos, color[pos]);
change(pos, col);
ans += get(pos, color[pos]);
write(ans);
putchar('\n');
}
}