B. so easy
题目链接
#include
using namespace std;
typedef long long LL;
unordered_map mp;
int x,n,q,op;
int Find(int x){
return mp.count(x) ? mp[x] = Find(mp[x]) : x;
}
int main(){
scanf("%d %d",&n,&q);
while(q--){
scanf("%d %d",&op,&x);
if(op == 1) mp[x] = x + 1;
else printf("%d\n", Find(x));
}
return 0;
}
C. Buy Watermelon
题目链接
#include
#include
#include
#include
#define LL long long
#define uLL unsigned long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(2)
int max(int x, int y) {if(x > y) return x; return y;}
int min(int x, int y) {if(x > y) return y; return x;}
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 3.1415927;
int main() {
int n;
cin >> n;
if(n % 2 == 0 && n != 2) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
D. Carneginon
题目链接
#include
#include
#include
#include
#define LL long long
#define uLL unsigned long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(2)
int max(int x, int y) {if(x > y) return x; return y;}
int min(int x, int y) {if(x > y) return y; return x;}
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 3.1415927;
char st[100005];
char dt[100005];
int Next[100005];
void getnext(char b[], int len_b) {//求的是模式串的next
int i, j = 0;
for(i = 1; i < len_b; ++i) {
while(j && b[i] != b[j]) j = Next[j];
if(b[i] == b[j]) j += 1;
Next[i + 1] = j;
}
}
int kmp(char b[], int len_b, char a[], int len_a) {
int i, j = 0;
for(i = 0; i < len_a; ++i) {
while(j && a[i] != b[j]) j = Next[j];
if(a[i] == b[j]) j += 1;
if(j == len_b) {
return 1;
// j = next[j];
}
}
return 0;
}
int main() {
scanf("%s", st);
int q, len = strlen(st);
scanf("%d", &q);
while(q--) {
scanf("%s", dt);
int l = strlen(dt);
memset(Next, 0, sizeof(Next));
if(l == len) {
if(strcmp(dt, st) == 0) printf("jntm!\n");
else printf("friend!\n");
} else if(len > l) {
getnext(dt, l);
if(kmp(dt, l, st, len)) printf("my child!\n");
else printf("oh, child!\n");
} else {
getnext(st, len);
if(kmp(st, len, dt, l)) printf("my teacher!\n");
else printf("senior!\n");
}
}
return 0;
}
E. XKC’s basketball team
题目链接
#include
#include
#include
#include
#define LL long long
#define uLL unsigned long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(2)
int max(int x, int y) {if(x > y) return x; return y;}
int min(int x, int y) {if(x > y) return y; return x;}
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 3.1415927;
struct node {
int l, r, m;
};
node f[500005 * 4];
int a[500005];
int b[500005];
int n, m;
void Build(int i, int l, int r) {
f[i].l = l, f[i].r = r;
if(l == r) {
f[i].m = a[l];
return ;
}
int mid = l + r >> 1;
Build(i * 2, l, mid);
Build(i * 2 + 1, mid + 1, r);
f[i].m = max(f[i * 2].m, f[i * 2 + 1].m);
}
int Query(int i, int l, int r, int k) {
if(f[i].l == f[i].r) return f[i].l;
int mid = f[i].l + f[i].r >> 1;
if(f[i * 2 + 1].m >= k) {
return Query(i * 2 + 1, l, r, k);
} else if(l <= mid && f[i * 2].m >= k) {
return Query(i * 2, l, r, k);
} else
return -1;
}
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
Build(1, 1, n);
int cnt;
for(int i = 1; i <= n; ++i) {
if(i == n) cnt = -1;
else cnt = Query(1, i + 1, n, a[i] + m);
if(cnt != -1)
cnt -= i + 1;
printf("%d%c", cnt, i == n ? '\n' : ' ');
}
return 0;
}