牛客国庆集训派对Day5 Solution

A    璀璨光滑

留坑。

 

B    电音之王

蒙特马利大数乘模运算

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 typedef long long ll;
 5 typedef unsigned long long u64;
 6 typedef __int128_t i128;
 7 typedef __uint128_t u128;
 8 
 9 struct Mod64 {
10     Mod64() :n_(0) {}
11     Mod64(u64 n) :n_(init(n)) {}
12     static u64 init(u64 w) { return reduce(u128(w) * r2); }
13     static void set_mod(u64 m) {
14         mod = m; assert(mod & 1);
15         inv = m; for (int i = 0; i < 5; ++i) inv *= 2 - inv * m;
16         r2 = -u128(m) % m;
17     }
18     static u64 reduce(u128 x) {
19         u64 y = u64(x >> 64) - u64((u128(u64(x)*inv)*mod) >> 64);
20         return ll(y)<0 ? y + mod : y;
21     }
22     Mod64& operator += (Mod64 rhs) { n_ += rhs.n_ - mod; if (ll(n_)<0) n_ += mod; return *this; }
23     Mod64 operator + (Mod64 rhs) const { return Mod64(*this) += rhs; }
24     Mod64& operator -= (Mod64 rhs) { n_ -= rhs.n_; if (ll(n_)<0) n_ += mod; return *this; }
25     Mod64 operator - (Mod64 rhs) const { return Mod64(*this) -= rhs; }
26     Mod64& operator *= (Mod64 rhs) { n_ = reduce(u128(n_)*rhs.n_); return *this; }
27     Mod64 operator * (Mod64 rhs) const { return Mod64(*this) *= rhs; }
28     u64 get() const { return reduce(n_); }
29     static u64 mod, inv, r2;
30     u64 n_;
31 };
32 
33 u64 Mod64::mod, Mod64::inv, Mod64::r2;
34 
35 
36 int t, k;
37 u64 A0, A1, M0, M1, C, M;
38 
39 void Run()
40 {
41     scanf("%d", &t);
42     while (t--)
43     {
44         scanf("%llu%llu%llu%llu%llu%llu%d", &A0, &A1, &M0, &M1, &C, &M, &k);
45         Mod64::set_mod(M);
46         Mod64 a0(A0), a1(A1), m0(M0), m1(M1), c(C), ans(1), a2(0);
47         ans *= a0; ans *= a1;
48         for (int i = 2; i <= k; ++i)
49         {
50             a2 = a1;
51             a1 = m0 * a1 + m1 * a0 + c;
52             a0 = a2;
53             ans *= a1;
54         }
55         printf("%llu\n", ans.get());
56     }
57 }
58 
59 int main()
60 {
61     #ifdef LOCAL
62         freopen("Test.in", "r", stdin);
63     #endif
64 
65     Run();
66     return 0;
67 }
View Code

 

 

C    萌新拆塔

留坑。

 

D    奇迹暖婊

留坑。

 

E    风花雪月

留坑。

 

F    双倍掉率

留坑。

 

G    贵族用户

枚举VIP等级,注意精度问题 不要用(1-p * 0.01) 用 (100 - p) * 1.0 / 100

 1 #include<bits/stdc++.h>
 2  
 3 using namespace std;
 4  
 5 const int maxn = 1e2 + 10;
 6  
 7 int m, k;
 8 int a[maxn], p[maxn], c[maxn], d[maxn];
 9  
10 int main()
11 {
12     int t;
13     scanf("%d", &t);
14     while(t--)
15     {
16         scanf("%d %d", &m, &k);
17         for(int i = 1; i <= m; ++i) scanf("%d %d", a + i, p + i);
18         for(int i = 1; i <= k; ++i) scanf("%d %d", c + i, d + i);
19         int ans = 0x3f3f3f3f;
20         //for(int i = 1; i <= k; ++i) ans += c[i] * d[i];
21         for(int i = 0; i <= m; ++i)
22         {
23             int res = 0;
24             for(int j = 1; j <= k; ++j)
25             {
26                 int tmp = (int)ceil(d[j] * (100.0 - p[i]) / 100.0);
27                 res += tmp * c[j];
28             }
29             if(res < a[i]) res = a[i];
30             ans = min(ans, res);
31         }
32         ans = (int)ceil(ans * 0.1);
33         printf("%d\n", ans);
34     }
35     return 0;
36 }
View Code

 

H    我不爱她

留坑。

 

I    人渣本愿

留坑。

 

J    友谊巨轮

用线段树维护每个人对其他人的聊天记录,然后取max上去,但是开1e5棵线段树肯定空间爆炸,考虑动态开点,每次最多开logn个结点

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 
  4 #define N 100010
  5 #define ll long long
  6 
  7 int t, n, m, k;
  8 int root[N], res;  
  9 
 10 struct SEG
 11 {
 12     #define M N * 35
 13     int cnt, lson[M], rson[M];
 14     struct node
 15     {
 16         int tm, pos;
 17         ll Max;
 18         bool operator < (const node &r) const
 19         {
 20             return Max == r.Max ? tm < r.tm : Max < r.Max;
 21         }
 22     }a[M];
 23 
 24     void pushup(int id)
 25     {
 26         a[id] = max(a[lson[id]], a[rson[id]]);
 27     }
 28 
 29     void update(int &root, int l, int r, ll val, int tm, int pos)
 30     {
 31         if (!root)
 32         {
 33             root = ++cnt;
 34             lson[root] = rson[root] = 0;
 35             a[root].Max = a[root].tm = a[root].pos = 0;
 36         }
 37         if (l == r)
 38         {
 39             a[root].Max += val;
 40             a[root].tm = max(a[root].tm, tm);
 41             a[root].pos = pos;
 42             return;
 43         }
 44         int mid = (l + r) >> 1;
 45         if (pos <= mid) update(lson[root], l, mid, val, tm, pos);
 46         else update(rson[root], mid + 1, r, val, tm, pos);
 47         pushup(root);
 48     }
 49 }segtree;
 50 
 51 void Init()
 52 {
 53     segtree.cnt = 0;
 54     memset(root, 0, sizeof root);
 55     res = 0;
 56 }
 57 
 58 struct OP
 59 {
 60     int a, b, c, tm;
 61     void scan(int tm)
 62     {
 63         this->tm = tm;
 64         scanf("%d%d%d", &a, &b, &c);
 65     }
 66 }op[N];
 67 
 68 void update(int a, int b, int c, int tm)
 69 {
 70     int bef = segtree.a[root[a]].pos;
 71     segtree.update(root[a], 1, n, c, tm, b);
 72     int now = segtree.a[root[a]].pos;
 73     if (bef == now) return;
 74     if (bef) 
 75     {
 76         if (segtree.a[root[bef]].pos == a) ++res;
 77         else --res;
 78     }
 79     if (now)
 80     {
 81         if (segtree.a[root[now]].pos == a) --res;
 82         else ++res; 
 83     }
 84 
 85 }
 86 
 87 void Run()
 88 {
 89     segtree.a[0].tm = 1000000;  // 防止取max操作时误把空节点pushup上去
 90     scanf("%d", &t);
 91     while (t--)
 92     {
 93         Init();
 94         scanf("%d%d%d", &n, &k, &m);
 95         for (int i = 1; i <= k; ++i)
 96         {
 97             op[i].scan(i);
 98             update(op[i].a, op[i].b, op[i].c, i);
 99             update(op[i].b, op[i].a, op[i].c, i);
100             if (i > m)
101             { 
102                 update(op[i - m].a, op[i - m].b, -op[i - m].c, i - m);
103                 update(op[i - m].b, op[i - m].a, -op[i - m].c, i - m);
104             }
105             printf("%d\n", res);
106         }
107     }
108 }
109 
110 int main()
111 {
112     #ifdef LOCAL
113         freopen("Test.in", "r", stdin);
114     #endif
115 
116     Run();
117     return 0;
118 }
View Code

 

 

K    最后战役

留坑。

 

L    数论之神

两个规律,在代码中。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3  
 4 #define ll long long
 5  
 6 int T;
 7 ll n, k;
 8  
 9 int main()
10 {
11     scanf("%d", &T);
12     while (T--)
13     {
14         scanf("%lld%lld", &n, &k);
15         ll t = (ll)sqrt(n);
16 //      cout << t << endl;
17         ll num = t * (t + 1) <= n ? 2 * t : 2 * t - 1;
18         k = num - k + 1;
19         ll K = k <= t ? k : n / (num - k + 1);
20         printf("%lld %lld\n", num, K);
21     }
22     return 0;
23 }
View Code

 

posted @ 2018-10-05 16:57  Dup4  阅读(320)  评论(0编辑  收藏  举报