PS: This do not want to make friends.
F.Final Exam
Meaning of the questions:
There \ (n \) course upcoming exam, there \ (m \) points for the assignment, if the score of a course of \ (the X-\) , then it would need to \ (x + 1 \) hours to review.
Now your goal is too \ (k \) course, ask how time can be assigned to review promised \ (k \) course and review the minimum time.
PS: The teacher may be for you based on your review time.
Idea:
It is a question of autistic ...
- The teacher is not a true test you review the most \ (k-1 \) course in favor of the points allocated to the rest of the \ (n-k + 1 \ ) course;
- You clearly aware of this, and to develop countermeasures: Review minimal \ (n-k + 1 \ ) course assignment \ (m + 1 \) hour, thinking you can escape unharmed;
- Teachers now can not get you, and you win.
- But at least as much time?
- This certainly I \ (n-k + 1 \ ) course mean that the maximum value can be assigned a minimum, you wit a count, the maximum time to review \ (\ frac {m} { n-k + 1} +1 \) It can be.
- Therefore, the answer is \ ((. 1-K) (\ {n-FRAC {m}} + 1'd. 1-K +). 1-m + \) .
Teacher to Tian Ji's horse, but fortunately you have enough time ...
Code
Please write it by yourself.
J.Just Repeat
Meaning of the questions:
Two people play the game of chance.
Now everyone has some hand colored cards, two people take turns to play a card, but can not hit the opponent has been playing out the color of the card.
Q. Who will ultimately win.
Ideas:
a man shot another man after a card can not be used this color card, equivalent to another person still be used, but we have a few extra cards.
Therefore, by \ (cnt1 [i] + cnt2 [i] \) to sort, then the process can be simulated.
Code
#include <bits/stdc++.h>
#define MP make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 2e5 + 5;
int T, n, m, p;
ull k1, k2;
ull rng() {
ull k3 = k1, k4 = k2;
k1 = k4;
k3 ^= k3 << 23;
k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
return k2 + k4;
}
int a[N], b[N], c[N];
int cnta[N], cntb[N];
pii d[N];
int resa, resb, mod;
void Hash() {
c[0] = 0;
for(int i = 1; i <= n; i++) c[++c[0]] = a[i];
for(int i = 1; i <= m; i++) c[++c[0]] = b[i];
sort(c + 1, c + c[0] + 1);
c[0] = unique(c + 1, c + c[0] + 1) - c - 1;
for(int i = 1; i <= c[0]; i++) cnta[i] = cntb[i] = 0;
for(int i = 1; i <= n; i++) a[i] = lower_bound(c + 1, c + c[0] + 1, a[i]) - c, cnta[a[i]]++;
for(int i = 1; i <= m; i++) b[i] = lower_bound(c + 1, c + c[0] + 1, b[i]) - c, cntb[b[i]]++;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> T;
while(T--) {
cin >> n >> m >> p;
if(p == 1) {
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) cin >> b[i];
} else {
cin >> k1 >> k2 >> mod;
for(int i = 1; i <= n; i++) a[i] = rng() % mod;
cin >> k1 >> k2 >> mod;
for(int i = 1; i <= m; i++) b[i] = rng() % mod;
}
Hash();
int tot = 0;
for(int i = 1; i <= c[0]; i++) {
if(cnta[i] && cntb[i]) {
d[++tot] = MP(cnta[i] + cntb[i], cnta[i]);
}
}
sort(d + 1 , d + tot + 1);
int cur = 1; resa = n, resb = m;
for(int i = tot; i; i--) {
if(cur & 1) {
resa--, resb -= d[i].first - d[i].second;
} else {
resb--, resa -= d[i].second;
}
cur ^= 1;
}
if(cur) {
if(resa > resb) cout << "Cuber QQ" << '\n';
else cout << "Quber CC" << '\n';
} else {
if(resb > resa) cout << "Quber CC" << '\n';
else cout << "Cuber QQ" << '\n';
}
}
return 0;
}
K.Kejin Player
Routine expect quite a recursive problem.
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500005, MOD = 1e9 + 7;
struct Istream {
template <class T>
Istream &operator >>(T &x) {
static char ch;static bool neg;
for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
x=neg?-x:x;
return *this;
}
}fin;
struct Ostream {
template <class T>
Ostream &operator <<(T x) {
x<0 && (putchar('-'),x=-x);
static char stack[233];static int top;
for(top=0;x;stack[++top]=x%10+'0',x/=10);
for(top==0 && (stack[top=1]='0');top;putchar(stack[top--]));
return *this;
}
Ostream &operator <<(char ch) {
putchar(ch);
return *this;
}
}fout;
int T, n, q;
ll sum[N];
ll qp(ll a, ll b) {
ll ans = 1;
while(b) {
if(b & 1) ans = ans * a % MOD;
a = a * a % MOD ;
b >>= 1;
}
return ans;
}
int main() {
// ios::sync_with_stdio(false); cin.tie(0);
fin >> T;
while(T--) {
fin >> n >> q;
for(int i = 1; i <= n; i++) {
ll r, s, x, a;
fin >> r >> s >> x >> a;
ll p = r * qp(s, MOD - 2) % MOD;
ll ans = (a * qp(p, MOD - 2) % MOD + ((1 - p) * qp(p, MOD - 2) % MOD * (sum[i - 1] - sum[x - 1]) % MOD + MOD) % MOD) % MOD;
sum[i] = (ans + sum[i - 1]) % MOD;
}
while(q--) {
int l, r; fin >> l >> r; r--;
fout << ((sum[r] - sum[l - 1]) % MOD + MOD) % MOD << '\n';
}
}
return 0;
}