11/16
听了 jxj 讲数学。怎么这么难,具体可以看这篇笔记。
11/17
等会写。
11/23
https://qdezoj.cpolar.cn/d/tigao/contest/6b02fb2c238f2366bb435789
http://47.113.203.55/contest/6aff9e9d973eae2699628565
travel
cargo
recall
11/24
https://qdezoj.cpolar.cn/d/tigao/contest/6b0400dc238f2366bb4739bc
minsparse
从高位往低位贪,如果 和 的这一位相同那么就不能动,直到遇到不同的一位,此时一定 这一位是 , 这一位是 ,记这一位前的 的个数是 。后面展开分讨。
-
如果 后面有 个 :那么保留前面所有的 ,后面不添加 即是最优解,那么最大最小值都是 。
-
如果 后面有 个 :最小的 的个数即是 ,那么把小答案后面的 放在原位,大答案取不一样的那一位 即可。
-
如果 后面有多个 :大答案的处理同上,小答案取后面第一个 的前一位为 可以保证 的个数最少并且是小答案。
code
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define debug(x) cerr<<"debug "<<__LINE__<<":"<<#x<<" = "<<x<<"\n"
#define For(i,a,b) for(int i = a;i<=b;i++)
#define Rof(i,a,b) for(int i = a;i>=b;i--)
inline ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
inline void write(ll x){if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
int main(){
freopen("minsparse.in","r",stdin);
freopen("minsparse.out","w",stdout);
//std::ios::sync_with_stdio(false);
//std::cin.tie(nullptr);
int q = read();
while(q--){
ll l = read(),r = read();
ll pos = 60;
while(pos>=0 && (l&(1ll<<pos)) == (r&(1ll<<pos))) pos--;
ll cnt = 0,num;
Rof(i,pos-1,0){
if((1ll<<i)&l){
cnt++;
if(cnt == 1) num = i+1;
}
}
if(cnt == 0){
write(l);
putchar(' ');
write(l);
putchar('\n');
}
else if(cnt == 1){
write(l);
ll ans = 0;
//pos-1~0全部置为0
For(i,pos,60){
if((1ll<<i)&r) ans |= (1ll<<i);
}
putchar(' ');
write(ans);
putchar('\n');
}
else{
ll ans = 0,res = 0;
For(i,pos,60){
if((1ll<<i)&r) ans |= (1ll<<i);
}
For(i,pos+1,60) if((1ll<<i)&l) res|=(1ll<<i);
res|=(1ll<<(num));
write(res);
putchar(' ');
write(ans);
putchar('\n');
}
}
return 0;
}
P12780 [ICPC 2024 Yokohama R] Omnes Viae Yokohamam Ducunt?
https://qdezoj.cpolar.cn/d/tigao/p/T7015
怎么还有 road?!
对于一个点 ,它连向它的子树的边一定会在它子树中所有的点上算一遍贡献。所以求出 号点到所有点的最短路,每个点的贡献就是最短路长度乘上边权,答案就是 (EZOJ题面)。
code
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define pii pair<int,int>
#define debug(x) cerr<<"debug "<<__LINE__<<":"<<#x<<" = "<<x<<"\n"
#define For(i,a,b) for(int i = a;i<=b;i++)
#define Rof(i,a,b) for(int i = a;i>=b;i--)
inline ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
inline void write(ll x){if(x<0){putchar('-');x=-x;}if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
struct edge{
int v,w;
};
struct node{
int dis,u;
bool operator>(const node &a) const {return dis>a.dis;}
};
vector<edge> g[100005];
int dis[100005],a[100005];
bool vis[100005];
priority_queue<node,vector<node>,greater<node>> q;
void dij(int s){
memset(dis,0x3f,sizeof(dis));
dis[s] = 0;
q.push({0,s});
while(!q.empty()){
int u = q.top().u;
q.pop();
if(vis[u]) continue;
vis[u] = 1;
for(auto it:g[u]){
int v = it.v,w = it.w;
if(dis[v]>dis[u]+w){
dis[v] = dis[u]+w;
q.push({dis[v],v});
}
}
}
}
signed main(){
//freopen("road.in","r",stdin);
//freopen("road.out","w",stdout);
//std::ios::sync_with_stdio(false);
//std::cin.tie(nullptr);
int n = read(),m = read();
For(i,1,n){
a[i] = read();
}
For(i,1,m){
int u = read(),v = read(),w = read();
g[u].push_back({v,w});
g[v].push_back({u,w});
}
dij(1);
ll ans = 0;
For(i,1,n){
ans+=dis[i]*a[i];
}
write(ans);
return 0;
}