传送门:https://atcoder.jp/contests/abc165/tasks
A
#include<bits/stdc++.h>
using namespace std;
int main(){
int k, a, b; cin>>k>>a>>b;
for(int i=a; i<=b; i++) if(i%k==0){
puts("OK");
return 0;
}
puts("NG");
return 0;
}
B
不要做精度战士了好吗qwq
#include<bits/stdc++.h>
using namespace std;
int n, m, q;
struct node{
int l, r, d, v;
}e[55];
int tmp;
int a[15];
void dfs(int u, int k){
if(u==n+1){
int t=0;
for(int i=1; i<=q; i++) if(a[e[i].r]-a[e[i].l]==e[i].d) t+=e[i].v;
tmp=max(tmp, t);
return;
}
a[u]=k;
for(int i=k; i<=m; i++)
dfs(u+1, i);
}
int main(){
cin>>n>>m>>q;
for(int i=1; i<=q; i++){
int a, b, c, d; cin>>a>>b>>c>>d;
e[i]={a, b, c, d};
}
int res=0;
for(int i=1; i<=m; i++){
tmp=0;
dfs(1, i);
res=max(res, tmp);
}
cout<<res<<endl;
return 0;
}
C
注意到值域很小,直接暴力。
#include<bits/stdc++.h>
using namespace std;
int n, m, q;
struct node{
int l, r, d, v;
}e[55];
int tmp;
int a[15];
void dfs(int u, int k){
if(u==n+1){
int t=0;
for(int i=1; i<=q; i++) if(a[e[i].r]-a[e[i].l]==e[i].d) t+=e[i].v;
tmp=max(tmp, t);
return;
}
a[u]=k;
for(int i=k; i<=m; i++)
dfs(u+1, i);
}
int main(){
cin>>n>>m>>q;
for(int i=1; i<=q; i++){
int a, b, c, d; cin>>a>>b>>c>>d;
e[i]={a, b, c, d};
}
int res=0;
for(int i=1; i<=m; i++){
tmp=0;
dfs(1, i);
res=max(res, tmp);
}
cout<<res<<endl;
return 0;
}
D
推式子。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '
'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define int long long
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
int a, b, n;
signed main(){
cin>>a>>b>>n;
int r=min(n, b-1);
cout<<a*r/b<<endl;
return 0;
}
E
奇怪的构造题,奇数情况很简单,但偶数情况很难,待补。
F
直接按 dfs 序搞即可,用树状数组维护,注意到回溯的时候无法原路修改,那我们就拿个栈记录一下历史值,回溯时赋回去即可。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '
'
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define int long long
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=2e5+5, M=N<<1;
struct node{
int to, next;
}e[M];
int h[N], tot;
void add(int u, int v){
e[tot].to=v, e[tot].next=h[u], h[u]=tot++;
}
int w[N], n;
int res[N];
vector<int> nums;
int a[N];
int find(int x){
return lower_bound(all(nums), x)-nums.begin()+1;
}
int tr[N];
int lowbit(int x){return x&-x;}
int query(int p){
int res=0;
for(; p; p-=lowbit(p)) res=max(res, tr[p]);
return res;
}
struct Buf{
int p, v;
}stk[N][25];
int top, cnt[N];
void update(int p, int v){
++top;
for(; p<N; p+=lowbit(p)){
++cnt[top];
stk[top][cnt[top]].p=p;
stk[top][cnt[top]].v=tr[p];
tr[p]=max(tr[p], v);
}
}
void reset(){
rep(i,1,cnt[top]){
int p=stk[top][i].p;
int v=stk[top][i].v;
stk[top][i]={0, 0};
tr[p]=v;
}
cnt[top]=0, top--;
}
void dfs(int u, int fa){
res[u]=1+query(a[u]);
update(a[u]+1, res[u]);
for(int i=h[u]; ~i; i=e[i].next){
int go=e[i].to;
if(go==fa) continue;
dfs(go, u);
}
reset();
}
void work(int u, int fa){
res[u]=max(res[u], res[fa]);
for(int i=h[u]; ~i; i=e[i].next) if(e[i].to!=fa) work(e[i].to, u);
}
signed main(){
memset(h, -1, sizeof h);
cin>>n;
rep(i,1,n) read(w[i]), nums.pb(w[i]);
sort(all(nums));
nums.erase(unique(all(nums)), nums.end());
rep(i,1,n) a[i]=find(w[i]);
rep(i,1,n-1){
int u, v; read(u), read(v);
add(u, v), add(v, u);
}
dfs(1, 0);
work(1, 0);
rep(i,1,n) cout<<res[i]<<endl;
return 0;
}