J Ball:
解析:签到题,略
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <sstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stdio.h>
#include <tuple>
using namespace std;
typedef long long LL;
//#define int LL
#define ld long double
const LL INF = 0x3f3f3f3f3f3f3f3f;
typedef unsigned long long ULL;
typedef pair<long long, long long> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int inf = 0x3f3f3f3f;
const LL Mod = 998244353;
const ld eps = 1e-12;
const int N = 5e5 + 10, M = 1e6 + 10;
int l, x, y;
ld get(int xx,int yy) {
ld a = xx - x, b = yy - y;
return sqrt(a * a + b * b);
}
signed main() {
int T;
cin >> T;
while (T--) {
scanf("%d%d%d", &l, &x, &y);
ld dist = get( 0, 0);
//cout << "______________" << dist << endl;
if ((ld)l - dist >= 0) {
printf("Yes\n");
printf("%.6lf\n", 0);
continue;
}
dist = get(l, 0);
//cout << "______________" << dist << endl;
if (l - dist >=0) {
printf("Yes\n");
printf("%.6lf\n", l);
continue;
}
printf("No\n");
}
return 0;
}
I Fight Against the Monster
解析:签到题,略
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <sstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stdio.h>
#include <tuple>
using namespace std;
typedef long long LL;
#define int LL
#define ld long double
const LL INF = 0x3f3f3f3f3f3f3f3f;
typedef unsigned long long ULL;
typedef pair<long long, long long> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int inf = 0x3f3f3f3f;
const LL Mod = 998244353;
const ld eps = 1e-12;
const int N = 5e5 + 10, M = 1e6 + 10;
int m, k, h;
bool check(int mid) {
int cnt = (mid - m) / (m - k) + 1;
int sum = mid + cnt * k;
return sum >= h;
}
signed main() {
int T;
cin >> T;
while (T--) {
scanf("%lld%lld%lld", &m, &k, &h);
if (m == k||h<=m) {
printf("%lld\n", min(m, h));
continue;
}
int l = m, r = h, ret = h;
while (l <= r) {
int mid = l + (r - l) / 2;
if (check(mid)) {
ret = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
printf("%lld\n", ret);
}
return 0;
}
/*
4
1 1 1000000000
2 1 1000000000
2 2 1000000000
4 4 1000000000
*/
D Interval Selection
对于求区间个数的问题一般是固定一个端点,然后求另一个合法端点的个数。
从左往右进行操作,对于当前点 x 做为右端点的情况下,从左往右数第 k 到第 k+1 个 x 的区间都是合法的左端点,其余都是不合法的,每次求出所有合法区间的交,就是答案区间的左端点的合法位置。
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <sstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stdio.h>
#include <tuple>
using namespace std;
typedef long long LL;
//#define int LL
#define ld long double
const LL INF = 0x3f3f3f3f3f3f3f3f;
typedef unsigned long long ULL;
typedef pair<long long, long long> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int inf = 0x3f3f3f3f;
const LL Mod = 998244353;
const ld eps = 1e-12;
const int N = 5e5 + 10, M = 1e6 + 10;
int n,k;
int A[N];
struct TREE {
int l, r;
int num, cnt, lazy;
}tr[N << 2];
vector<int>p[N];
map<int, int>mp;
#define ls u<<1
#define rs u<<1|1
void up(int u) {
tr[u].num = min(tr[ls].num, tr[rs].num);
tr[u].cnt = 0;
if (tr[u].num == tr[ls].num) {
tr[u].cnt = tr[ls].cnt;
}
if (tr[u].num == tr[rs].num) {
tr[u].cnt += tr[rs].cnt;
}
}
void build(int u, int l, int r) {
tr[u].l = l, tr[u].r = r;
tr[u].lazy = 0;
if (l == r) {
tr[u].num = 0;
tr[u].cnt = 1;
return;
}
int mid = l + r >> 1;
build(ls, l, mid), build(rs, mid + 1, r);
up(u);
}
void pushdown(int u) {
if (tr[u].lazy) {
tr[ls].lazy += tr[u].lazy;
tr[ls].num += tr[u].lazy;
tr[rs].lazy += tr[u].lazy;
tr[rs].num += tr[u].lazy;
tr[u].lazy = 0;
}
}
void modify(int u, int l, int r, int d) {
if (tr[u].l >= l && tr[u].r <= r) {
tr[u].num += d;
tr[u].lazy += d;
return;
}
int mid = tr[u].l + tr[u].r >> 1;
pushdown(u);
if (l <= mid)
modify(ls, l, r, d);
if (r > mid)
modify(rs, l, r, d);
up(u);
}
int query(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) {
return tr[u].num == 0 ? tr[u].cnt : 0;
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
int ret = 0;
if (l <= mid) {
ret = query(ls, l, r);
}
if (r > mid) {
ret += query(rs, l, r);
}
return ret;
}
int get(vector<int>&t,int x) {
return t[t.size() - x];
}
int cn = 0;
int getid(int a) {
if (mp[a])return mp[a];
mp[a] = ++cn;
return cn;
}
signed main() {
int T;
cin >> T;
while (T--) {
mp.clear();
cn = 0;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
A[i] = getid(a);
p[i].clear();
p[i].push_back(0);
}
build(1, 1, n);
//int up = k + 1;
LL ans = 0;
for (int i = 1; i <= n; i++) {
//cout << ";;;;;;;;;;:::::::::::::::::::: " << i << endl;
if (p[A[i]].size() >= k + 1) {
modify(1, get(p[A[i]], k + 1) + 1, get(p[A[i]], k), 1);
//cout << "______________" << get(p[A[i]], k + 1) + 1 << " " << get(p[A[i]], k) << endl;
}
p[A[i]].push_back(i);
modify(1, get(p[A[i]], 2) + 1, get(p[A[i]], 1), 1);
//cout << "++++++++++++++" << get(p[A[i]], 2) + 1 << " " << get(p[A[i]], 1) << endl;
if (p[A[i]].size() >= k + 1) {
modify(1, get(p[A[i]], k + 1) + 1, get(p[A[i]], k), -1);
//cout << "==============" << get(p[A[i]], k + 1) + 1 << " " << get(p[A[i]], k) << endl;
}
ans += query(1, 1, i);
//cout << "_________________" << query(1, 1, i) << endl;
}
printf("%lld\n", ans);
}
return 0;
}
/*
4
3 2
1 2 2
3 1
1 2 3
6 2
1 1 4 5 1 4
6 3
1 2 1 1 1 1
*/