D
签到题
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define vi vector<int> #define mod 1000000007 #define ld long double #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pll pair<ll,ll> #define pil pair<int,ll> #define pli pair<ll,int> #define pii pair<int,int> #define cd complex<double> #define ull unsigned long long #define base 1000000000000000000 #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define fio ios::sync_with_stdio(false);cin.tie(0) template<typename T> inline T const& MAX(T const &a,T const &b){return a>b?a:b;} template<typename T> inline T const& MIN(T const &a,T const &b){return a<b?a:b;} inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;} inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;} inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline 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;} inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8; const ll INF=0x3f3f3f3f3f3f3f3f; const int N=100000+10,maxn=400000+10,inf=0x3f3f3f3f; ll ans[N]; int main() { int T,cas=0; scanf("%d",&T); while(T--) { memset(ans,0,sizeof ans); int n,m,k; scanf("%d%d%d",&n,&m,&k); while(k--) { int a,b;ll c; scanf("%d%d%lld",&a,&b,&c); ans[b]=max(ans[b],c); } ll res=0; for(int i=1;i<=m;i++)res+=ans[i]; printf("Case #%d: %lld ",++cas,res); } return 0; } /******************** 2 2 3 3 1 2 1919 1 3 810 2 2 450 ********************/
A
直接模拟
#include<bits/stdc++.h> #define LL long long #define ll long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using namespace std; const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; int n; set<int> st[N]; int solve(int l, int r) { if(l + 1 == r) { int big1 = *st[l].rbegin(); int big2 = *st[r].rbegin(); if(big1 > big2) { st[l].erase(st[l].upper_bound(big2)); return l; } else { st[r].erase(st[r].upper_bound(big1)); return r; } } int mid = l + r >> 1; int lson = solve(l, mid); int rson = solve(mid + 1, r); int big1 = *st[lson].rbegin(); int big2 = *st[rson].rbegin(); if(big1 > big2) { st[lson].erase(st[lson].upper_bound(big2)); return lson; } else { st[rson].erase(st[rson].upper_bound(big1)); return rson; } } int main() { int T; scanf("%d", &T); for(int cas = 1; cas <= T; cas++) { scanf("%d", &n); for(int i = 0; i < (1 << n); i++) st[i].clear(); for(int i = 0; i < (1 << n); i++) { for(int j = 1; j <= n; j++) { int x; scanf("%d", &x); st[i].insert(x); } } printf("Case #%d: %d ", cas, solve(0, (1 << n) - 1) + 1); } return 0; } /* */
J
因为数据是随机的,挑出top30大的暴力check
#include<bits/stdc++.h> const int N = 1e7 +7; using namespace std; unsigned long long n, a, b, c, mx, mx2, mx3; unsigned int t, x, y, z; unsigned long long w[N]; int k = 30; bool cmp (const unsigned long long &a, const unsigned long long &b) { return a > b; } int main(){ int T; scanf("%d", &T); for(int cas = 1; cas <= T; cas++) { scanf("%llu%llu%llu%llu", &n, &a, &b, &c); x = a, y = b, z = c; for(int i = 0; i < n; ++i){ x ^= (x << 16); x ^= (x >> 5); x ^= (x << 1); t = x; x = y; y = z; z = (t ^ x ^ y); w[i] = z; } nth_element(w, w + min((int)n - 1, k - 1), w + n, cmp); unsigned long long ans = w[0]; for(int i = 0; i < min((int)n, k); i++) { for(int j = i + 1; j < min((int)n, k); j++) { ans = max(ans, w[i] / __gcd(w[i], w[j]) * w[j]); } } printf("Case #%d: %llu ", cas, ans); } return 0; } /* 1 5 3 4 8 */
C
队友找规律搞过去的。。。
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define fi first #define se second #define db double #define mp make_pair #define pb push_back #define pi acos(-1.0) #define ll long long #define vi vector<int> #define mod 998244353 #define ld long double #define C 0.5772156649 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #define pll pair<ll,ll> #define pil pair<int,ll> #define pli pair<ll,int> #define pii pair<int,int> //#define cd complex<double> #define ull unsigned long long #define base 1000000000000000000 #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define fio ios::sync_with_stdio(false);cin.tie(0) template<typename T> inline T const& MAX(T const &a,T const &b){return a>b?a:b;} template<typename T> inline T const& MIN(T const &a,T const &b){return a<b?a:b;} inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;} inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;} inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline 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;} inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const double eps=1e-8; const ll INF=0x3f3f3f3f3f3f3f3f; const int N=1000000+10,maxn=50000+10,inf=1e9; ll c[N],f[N], inv[N]; ll n,m; void init() { ll now=m%mod; f[n]=now;sub(now,1); for(int i=n-1;i>=0;i--) f[i]=f[i+1]*now%mod,sub(now,1); c[0]=1; for(int i=0;i<n-2;i++) { c[i+1]=c[i]*(n-2-i)%mod*inv[i+1]%mod; } } int main() { inv[1]=1; for(int i=2;i<N;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod; int T;scanf("%d",&T); for(int cas=1;cas<=T;cas++) { scanf("%lld%lld",&n,&m); if(n==1) { printf("Case #%d: %lld ",cas,m%mod); continue; } if(m==1) { printf("Case #%d: 1 ",cas); continue; } if(n<=m) { init(); ll ans=0; for(ll i=m-1,j=0,k=n;i>=m+1-n;k--,j++,i--) { add(ans,(i+1)%mod*c[j]%mod*f[k]%mod); // printf("%lld %lld %lld ",i+1,c[j],f[k]); } printf("Case #%d: %lld ",cas,ans); } else { swap(n,m); init(); ll ans=0; for(ll i=m-1,j=0,k=n;i>=m+1-n;k--,j++,i--) { add(ans,(i+1)%mod*c[j]%mod*f[k]%mod); // printf("%lld %lld %lld ",i+1,c[j],f[k]); } ans=ans*qp(m%mod,mod-2)%mod*n%mod; printf("Case #%d: %lld ",cas,ans); } } return 0; } /******************** 2 1000000 1000000000000000000 ********************/
补题*************************************************************************************
I
先把线段的问题转换成平面上点的问题,然后在线段树上归并,进行暴力删点。
感觉将线段转换成点的问题很巧妙。
#include<bits/stdc++.h> #define LL long long #define ll long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using namespace std; const int N = 2e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 998244353; int n, m, tot, ret, hs[N], is[N], pos[N]; pii a[N]; bool f; vector<pii> vec[N], v[N << 2]; void build(int l, int r, int rt) { v[rt].clear(); if(l == r) { v[rt] = vec[l]; vec[l].clear(); return; } int mid = l + r >> 1; build(l, mid, rt << 1); build(mid + 1, r, rt << 1 | 1); int p = 0, q = 0; while(p < v[rt << 1].size() && q < v[rt << 1 | 1].size()) { if(v[rt << 1][p] <= v[rt << 1 | 1][q]) v[rt].push_back(v[rt << 1][p++]); else v[rt].push_back(v[rt << 1 | 1][q++]); } while(p < v[rt << 1].size()) v[rt].push_back(v[rt << 1][p++]); while(q < v[rt << 1 | 1].size()) v[rt].push_back(v[rt << 1 | 1][q++]); } int query(int x, int l, int r, int rt, int num) { if(hs[l] > x) return 0; if(hs[r] <= x) { int ans = 0; while(v[rt].size() && v[rt].back().fi >= x) { int id = v[rt].back().se; if(!is[id]) { f = true; ans++; ret = 1ll * ret * id % mod; is[id] = num; } v[rt].pop_back(); } return ans; } int mid = l + r >> 1, ans = 0; ans = query(x, l, mid, rt << 1, num); if(hs[mid + 1] <= x) ans += query(x, mid + 1, r, rt << 1 | 1, num); return ans; } void init() { memset(is, 0, sizeof(is)); tot = 0; } int main() { int T; scanf("%d", &T); for(int cas = 1; cas <= T; cas++) { scanf("%d%d", &n, &m); init(); for(int i = 1; i <= n; i++) { scanf("%d%d", &a[i].fi, &a[i].se); hs[++tot] = a[i].fi; } sort(hs + 1, hs + 1 + tot); tot = unique(hs + 1, hs + 1 + tot) - hs - 1; for(int i = 1; i <= n; i++) { pos[i] = lower_bound(hs + 1, hs + 1 + tot, a[i].fi) - hs; vec[pos[i]].push_back(mk(a[i].se, i)); } for(int i = 1; i <= tot; i++) sort(vec[i].begin(), vec[i].end()); build(1, tot, 1); f = false; ret = 1; printf("Case #%d: ", cas); for(int i = 1; i <= m; i++) { int x; scanf("%d", &x); if(f) { x ^= ret; ret = 1; f = false; } printf("%d ", query(x, 1, tot, 1, i)); } for(int i = 1; i <= n; i++) printf("%d ", is[i]); puts(""); } return 0; } /* */