mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-12-19 21:51:44 +00:00
Compare commits
No commits in common. "1d1598fdc2c1df5fdac0b9efe85ee62274c3566b" and "5a9d1efd5d7febcd43524a2a2679397ae5f213df" have entirely different histories.
1d1598fdc2
...
5a9d1efd5d
@ -7,10 +7,7 @@
|
|||||||
#include <istream>
|
#include <istream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
// 引入这个头文件以使用 abs
|
using ll = int;
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
using ll = int; // 距离不会爆int,用int更快一点
|
|
||||||
|
|
||||||
const ll maxn=5e4+5,maxk=51,inf=1e9+7;
|
const ll maxn=5e4+5,maxk=51,inf=1e9+7;
|
||||||
ll n,k,b[maxn];
|
ll n,k,b[maxn];
|
||||||
@ -24,7 +21,7 @@ struct P{
|
|||||||
return step>o.step;
|
return step>o.step;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#define printf
|
||||||
int main(){
|
int main(){
|
||||||
std::iostream::sync_with_stdio(false);
|
std::iostream::sync_with_stdio(false);
|
||||||
std::cin.tie(nullptr);
|
std::cin.tie(nullptr);
|
||||||
@ -37,8 +34,6 @@ int main(){
|
|||||||
classp[b[i]].emplace_back(i);
|
classp[b[i]].emplace_back(i);
|
||||||
vis[i]=inf;
|
vis[i]=inf;
|
||||||
}
|
}
|
||||||
// 注意:classp 中的下标天然就是有序的(从小到大),所以不需要额外排序
|
|
||||||
|
|
||||||
for(ll i=1;i<=k;i++){
|
for(ll i=1;i<=k;i++){
|
||||||
for(ll j=1;j<=k;j++){
|
for(ll j=1;j<=k;j++){
|
||||||
char tmp;
|
char tmp;
|
||||||
@ -48,57 +43,27 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::priority_queue<P> pq;
|
std::priority_queue<P> pq;
|
||||||
pq.emplace(1,0);
|
pq.emplace(1,0);
|
||||||
// vis[1] = 0; // 严谨的Dijkstra最好在这里初始化,不过你的逻辑在下面判断也可以
|
|
||||||
|
|
||||||
while(pq.size()){
|
while(pq.size()){
|
||||||
auto[now,step]=pq.top();
|
auto[now,step]=pq.top();
|
||||||
pq.pop();
|
pq.pop();
|
||||||
|
if(vis[now]!=inf)continue;
|
||||||
// 这里的逻辑稍微调整一下,符合标准Dijkstra
|
vis[now]=std::min(step,vis[now]);
|
||||||
if(vis[now]!=inf) continue;
|
printf("dij now=%lld, step=%lld\n",now,step);
|
||||||
vis[now]=step;
|
|
||||||
|
|
||||||
if(now==n){
|
if(now==n){
|
||||||
std::cout<<step<<"\n";
|
std::cout<<step<<"\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
for(ll i:edg[b[now]]){
|
||||||
// --- 修改开始 ---
|
for(ll p:classp[i]){
|
||||||
for(ll target_breed : edg[b[now]]){
|
if(p==now)continue;
|
||||||
// 获取目标品种的所有位置列表
|
printf("%lld goto %lld\n",b[now],i);
|
||||||
const auto& vec = classp[target_breed];
|
ll nstep=step+std::abs(p-now);
|
||||||
if(vec.empty()) continue;
|
if(nstep>vis[p])continue;
|
||||||
|
pq.emplace(p,step+std::abs(p-now));
|
||||||
// 1. 找右边最近的一个 (第一个 > now 的位置)
|
|
||||||
auto it = std::upper_bound(vec.begin(), vec.end(), now);
|
|
||||||
if(it != vec.end()){
|
|
||||||
ll p = *it;
|
|
||||||
ll nstep = step + std::abs(p - now);
|
|
||||||
// 只有当新路径更短,且该点未被“关闭”(未vis)时才入队
|
|
||||||
// 注意:你之前的逻辑里 vis[p] 初始化是 inf,所以用 nstep < vis[p] 没问题
|
|
||||||
// 但要注意 vis 在你的代码里既做“已访问标记”又存“最短路”。
|
|
||||||
// 更安全的写法是只判断是否更优,因为如果 vis[p] 已经是更小的值,这里就不会进
|
|
||||||
if(vis[p] == inf) {
|
|
||||||
pq.emplace(p, nstep);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 找左边最近的一个 (第一个 < now 的位置)
|
|
||||||
// lower_bound 是 >= now,所以它的前一个就是 < now
|
|
||||||
auto it_l = std::lower_bound(vec.begin(), vec.end(), now);
|
|
||||||
if(it_l != vec.begin()){
|
|
||||||
it_l--; // 往前移一位
|
|
||||||
ll p = *it_l;
|
|
||||||
ll nstep = step + std::abs(p - now);
|
|
||||||
if(vis[p] == inf) {
|
|
||||||
pq.emplace(p, nstep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// --- 修改结束 ---
|
|
||||||
}
|
}
|
||||||
std::cout<<"-1\n";
|
std::cout<<"-1\n";
|
||||||
}
|
}
|
||||||
@ -1,3 +0,0 @@
|
|||||||
int main(){
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <set>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
ll n,k,ans;
|
|
||||||
std::vector<ll> ap,bp,cnt;
|
|
||||||
std::unordered_map<ll, ll> ans1,ans2;
|
|
||||||
std::set<ll> vis;
|
|
||||||
#define printf
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>k;
|
|
||||||
ap.resize(n+1),bp.resize(n+1),cnt.resize(n+1);
|
|
||||||
for(ll i=1;i<=k;i++){
|
|
||||||
ll tmp;
|
|
||||||
std::cin>>tmp;
|
|
||||||
ap[tmp]=i;
|
|
||||||
cnt[tmp]++;
|
|
||||||
vis.emplace(tmp);
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=k;i++){
|
|
||||||
ll tmp;
|
|
||||||
std::cin>>tmp;
|
|
||||||
cnt[tmp]++;
|
|
||||||
bp[tmp]=i;
|
|
||||||
if(cnt[tmp]==2){
|
|
||||||
printf("cnt[%lld]=%lld\n",tmp,cnt[tmp]);
|
|
||||||
ll diff=ap[tmp]-bp[tmp];
|
|
||||||
if(diff<0)diff+=k;
|
|
||||||
printf("diffa=%lld\n",diff);
|
|
||||||
ans1[diff]++;
|
|
||||||
ans=std::max({ans1[diff],ans});
|
|
||||||
|
|
||||||
diff=ap[tmp]-(k-bp[tmp]+1);
|
|
||||||
if (diff<0) {
|
|
||||||
diff+=k;
|
|
||||||
}
|
|
||||||
printf("diffb=%lld\n",diff);
|
|
||||||
ans2[diff]++;
|
|
||||||
ans=std::max({ans2[diff],ans});
|
|
||||||
}
|
|
||||||
vis.emplace(tmp);
|
|
||||||
}
|
|
||||||
printf("ans=%lld, vis.size()=%lld\n",ans,vis.size());
|
|
||||||
std::cout<<n-vis.size()+ans<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define printf
|
|
||||||
const ll inf=1e9+7;
|
|
||||||
ll n,l,a,b;
|
|
||||||
std::vector<ll> v,dp,diff;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>l>>a>>b;
|
|
||||||
v.resize(l+1);dp.resize(l+1,inf);diff.resize(l+2);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
ll s,e;
|
|
||||||
std::cin>>s>>e;
|
|
||||||
v[s]++,v[e]--;
|
|
||||||
diff[e]++;
|
|
||||||
}
|
|
||||||
dp[0]=0;
|
|
||||||
for(int i=2;i<=l;i+=2){
|
|
||||||
v[i-1]+=v[i-2];
|
|
||||||
v[i]+=v[i-1];
|
|
||||||
for(int j=a;j<=b&&i-j*2>=0;j++){
|
|
||||||
if(!v[i-j*2] || diff[i-j*2]==v[i-j*2-1]){
|
|
||||||
dp[i]=std::min(dp[i],dp[i-j*2]+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("now[%lld]=%lld\n",i,v[i]);
|
|
||||||
printf("dp[%lld]=%lld\n",i,dp[i]);
|
|
||||||
printf("diff[%lld]=%lld\n",i,diff[i]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
std::cout<<(dp[l]>=inf?-1:dp[l])<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define printf
|
|
||||||
const ll p=9901;
|
|
||||||
ll n,k;
|
|
||||||
std::vector<std::vector<ll>> dp;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>k;
|
|
||||||
dp.resize(n+1,std::vector<ll>(k+1));
|
|
||||||
for(ll i=1;i<=k;i++)dp[1][i]=1;
|
|
||||||
for(ll i=3;i<=n;i+=2){
|
|
||||||
for(ll j=2;j<=k;j++){
|
|
||||||
for(ll k=1;k<i;k+=2){
|
|
||||||
dp[i][j]+=dp[i-k-1][j-1]*dp[k][j-1]%p;
|
|
||||||
dp[i][j]%=p;
|
|
||||||
}
|
|
||||||
printf("dp[%lld][%lld]=%lld\n",i,j,dp[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<(dp[n][k]-dp[n][k-1]+p)%p<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
const int inf=1e9+7;
|
|
||||||
int n,m;
|
|
||||||
std::vector<int> a,dp,s;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>m;
|
|
||||||
a.resize(n+1);
|
|
||||||
dp.resize(n+1,inf);
|
|
||||||
s.resize(m+1);
|
|
||||||
|
|
||||||
for(int i=1;i<=n;i++)std::cin>>a[i];
|
|
||||||
dp[0]=0;
|
|
||||||
for(int i=1;i<=n;i++){
|
|
||||||
int size=0;
|
|
||||||
for(int j=i;j>=1&&size*size<=n;j--){
|
|
||||||
if(s[a[j]]!=i){
|
|
||||||
size++;
|
|
||||||
s[a[j]]=i;
|
|
||||||
}
|
|
||||||
dp[i]=std::min(dp[i],dp[j-1]+size*size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<dp[n]<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
ll n, m, r, ans;
|
|
||||||
std::vector<ll> a, b;
|
|
||||||
std::vector<std::vector<ll>> ea; // 只保留左到右的邻接表即可
|
|
||||||
std::vector<ll> dpa, dpb; // 不需要二维数组,一维即可
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
// 优化输入输出
|
|
||||||
std::ios::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin >> n >> m >> r;
|
|
||||||
|
|
||||||
// 调整大小
|
|
||||||
a.resize(n + 1);
|
|
||||||
b.resize(m + 1);
|
|
||||||
ea.resize(n + 1);
|
|
||||||
dpa.resize(n + 1);
|
|
||||||
dpb.resize(m + 1);
|
|
||||||
|
|
||||||
// 读入左岸权值并初始化 DP 和 ans
|
|
||||||
for (ll i = 1; i <= n; i++) {
|
|
||||||
std::cin >> a[i];
|
|
||||||
dpa[i] = a[i]; // 路径可以只包含这一个点
|
|
||||||
ans = std::max(ans, a[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读入右岸权值并初始化 DP 和 ans
|
|
||||||
for (ll i = 1; i <= m; i++) {
|
|
||||||
std::cin >> b[i];
|
|
||||||
dpb[i] = b[i]; // 路径可以只包含这一个点
|
|
||||||
ans = std::max(ans, b[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读入边,只存单向即可(左->右),后续通过排序处理顺序
|
|
||||||
for (ll i = 1; i <= r; i++) {
|
|
||||||
ll u, v;
|
|
||||||
std::cin >> u >> v;
|
|
||||||
ea[u].push_back(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 核心逻辑:按照左岸点 u 从小到大,右岸点 v 从小到大的顺序处理每一条边
|
|
||||||
// 这等同于正解中的 sort(e+1, e+r+1)
|
|
||||||
for (ll i = 1; i <= n; i++) {
|
|
||||||
// 对当前左岸点 i 连接的所有右岸点进行排序
|
|
||||||
std::sort(ea[i].begin(), ea[i].end());
|
|
||||||
|
|
||||||
for (ll j : ea[i]) {
|
|
||||||
// 暂存数值,避免更新顺序影响(同正解中的 t1, t2)
|
|
||||||
// 从右岸 j 走到 左岸 i
|
|
||||||
ll val_to_left = dpb[j] + a[i];
|
|
||||||
// 从左岸 i 走到 右岸 j
|
|
||||||
ll val_to_right = dpa[i] + b[j];
|
|
||||||
|
|
||||||
// 更新 DP 表
|
|
||||||
dpa[i] = std::max(dpa[i], val_to_left);
|
|
||||||
dpb[j] = std::max(dpb[j], val_to_right);
|
|
||||||
|
|
||||||
// 更新全局答案
|
|
||||||
ans = std::max({ans, dpa[i], dpb[j]});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << ans << "\n";
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
ll n;
|
|
||||||
std::vector<ll> a,b;
|
|
||||||
std::vector<std::vector<ll>> dp;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
std::cin>>n;
|
|
||||||
|
|
||||||
a.resize(n+1),b.resize(n+1),dp.resize(n+1,std::vector<ll>(n+1));
|
|
||||||
|
|
||||||
for(ll i=1;i<=n;i++)std::cin>>a[i];
|
|
||||||
for(ll i=1;i<=n;i++)std::cin>>b[i];
|
|
||||||
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
for(ll j=1;j<=n;j++){
|
|
||||||
if(std::abs(a[i]-b[j])<=4){
|
|
||||||
dp[i][j]=dp[i-1][j-1]+1;
|
|
||||||
}else{
|
|
||||||
dp[i][j]=std::max(dp[i-1][j],dp[i][j-1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<dp[n][n]<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
ll n,m,k;
|
|
||||||
const ll maxn=1000+7;
|
|
||||||
bool cow[maxn][maxn],g[maxn][maxn];
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>m>>k;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
ll x,y;
|
|
||||||
std::cin>>x>>y;
|
|
||||||
cow[x][y]=true;
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=m;i++){
|
|
||||||
ll x,y;
|
|
||||||
std::cin>>x>>y;
|
|
||||||
g[x][y]=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
ll n,m,v,e;
|
|
||||||
std::vector<std::vector<ll>> mp;
|
|
||||||
std::vector<ll> c,d;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>m>>v>>e;
|
|
||||||
mp.resize(v+1,std::vector<ll>(v+1));
|
|
||||||
c.resize(n+1);
|
|
||||||
d.resize(n+1);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>c[i];
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>d[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <queue>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int;
|
|
||||||
#define printf
|
|
||||||
#define pv(v)do{printf("[DEBUG] %s= %lld\n",#v,(v));}while(0)
|
|
||||||
|
|
||||||
ll n,m,q,u,v,t;
|
|
||||||
double p;
|
|
||||||
std::vector<ll> a;
|
|
||||||
std::priority_queue<ll> pq;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>m>>q>>u>>v>>t;
|
|
||||||
p=double(u)/double(v);
|
|
||||||
a.resize(n+1);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>a[i];
|
|
||||||
pq.emplace(a[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ll i=0;i<m;i++){ // 7e6*log(m)
|
|
||||||
pv(i);
|
|
||||||
ll qi=q*i,top=pq.top()+qi;
|
|
||||||
pv(pq.top());
|
|
||||||
pq.pop();
|
|
||||||
pv(top);
|
|
||||||
pv(qi);
|
|
||||||
ll a=p*top,b=top-a;
|
|
||||||
pq.emplace(a-qi-q);
|
|
||||||
pq.emplace(b-qi-q);
|
|
||||||
if((i+1)%t==0){
|
|
||||||
std::cout<<top<<" ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<"\n";
|
|
||||||
ll idx=1;
|
|
||||||
const ll qm=q*m;
|
|
||||||
while(pq.size()){
|
|
||||||
if(idx%t==0){
|
|
||||||
std::cout<<pq.top()+qm<<" ";
|
|
||||||
}
|
|
||||||
pq.pop();
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <map>
|
|
||||||
#include <random>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using ll = int64_t;
|
|
||||||
#define sl static inline
|
|
||||||
|
|
||||||
const int cnsize=3;
|
|
||||||
ll ltmp;
|
|
||||||
std::map<std::string, std::vector<std::string>> m;
|
|
||||||
std::vector<std::string> startw;
|
|
||||||
std::random_device rd;
|
|
||||||
std::mt19937 mt(rd());
|
|
||||||
std::unordered_set<std::string> old;
|
|
||||||
|
|
||||||
sl std::vector<std::string> stovs(const std::string &s){
|
|
||||||
std::vector<std::string> ret;
|
|
||||||
for(int i=0;i<s.size();i+=3){
|
|
||||||
std::string ns;
|
|
||||||
for(int j=0;j<cnsize&&i+j<s.size();j++){
|
|
||||||
ns=ns+s[i+j];
|
|
||||||
}
|
|
||||||
ret.emplace_back(ns);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
while(std::cin>>ltmp){
|
|
||||||
std::string b;
|
|
||||||
std::cin>>b;
|
|
||||||
std::vector<std::string> strs=stovs(b);
|
|
||||||
// for(auto &i:strs){
|
|
||||||
// std::cout<<i<<"\n";
|
|
||||||
// }
|
|
||||||
old.emplace(b);
|
|
||||||
startw.push_back(strs[0]);
|
|
||||||
for(int i=1;i<strs.size();i++){
|
|
||||||
m[strs[i-1]].push_back(strs[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uniform_int_distribution<int> uv(0,startw.size()-1);
|
|
||||||
for(int i=1;i<=20;i++){
|
|
||||||
// std::cout<<"i="<<i<<"\n";
|
|
||||||
std::string now=startw[uv(mt)];
|
|
||||||
std::string all;
|
|
||||||
for(int j=1;j<=4;j++){
|
|
||||||
all+=now;
|
|
||||||
// std::cout<<now;
|
|
||||||
if(m[now].size()==0)break;
|
|
||||||
std::uniform_int_distribution<int> uvm(0,m[now].size()-1);
|
|
||||||
now=m[now][uvm(mt)];
|
|
||||||
}
|
|
||||||
std::cout<<all;
|
|
||||||
if(old.count(all)){
|
|
||||||
std::cout<<" "<<"[is old]";
|
|
||||||
}
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,219 +0,0 @@
|
|||||||
1 一帆風順
|
|
||||||
2 一見如故
|
|
||||||
3 一清二楚
|
|
||||||
4 一塵不染
|
|
||||||
5 一落千丈
|
|
||||||
6 一成不變
|
|
||||||
7 一箭雙雕
|
|
||||||
8 一言難盡
|
|
||||||
9 一暴十寒
|
|
||||||
10 一絲不苟
|
|
||||||
|
|
||||||
11 九牛一毛
|
|
||||||
12 人山人海
|
|
||||||
13 人聲鼎沸
|
|
||||||
14 人跡罕至
|
|
||||||
15 人心難測
|
|
||||||
16 人才輩出
|
|
||||||
17 人定勝天
|
|
||||||
18 人浮於事
|
|
||||||
19 人情世故
|
|
||||||
20 人傑地靈
|
|
||||||
|
|
||||||
21 大公無私
|
|
||||||
22 大驚小怪
|
|
||||||
23 大材小用
|
|
||||||
24 大器晚成
|
|
||||||
25 大同小異
|
|
||||||
26 大張旗鼓
|
|
||||||
27 大言不慚
|
|
||||||
28 大快朵頤
|
|
||||||
29 大有可為
|
|
||||||
30 大惑不解
|
|
||||||
|
|
||||||
31 天南地北
|
|
||||||
32 天經地義
|
|
||||||
33 天馬行空
|
|
||||||
34 天衣無縫
|
|
||||||
35 天翻地覆
|
|
||||||
36 天長地久
|
|
||||||
37 天涯比鄰
|
|
||||||
38 天道酬勤
|
|
||||||
39 天人交戰
|
|
||||||
40 天花亂墜
|
|
||||||
|
|
||||||
41 心猿意馬
|
|
||||||
42 心神不寧
|
|
||||||
43 心滿意足
|
|
||||||
44 心急如焚
|
|
||||||
45 心安理得
|
|
||||||
46 心領神會
|
|
||||||
47 心血來潮
|
|
||||||
48 心花怒放
|
|
||||||
49 心甘情願
|
|
||||||
50 心驚膽戰
|
|
||||||
|
|
||||||
51 水落石出
|
|
||||||
52 水深火熱
|
|
||||||
53 水乳交融
|
|
||||||
54 水泄不通
|
|
||||||
55 水到渠成
|
|
||||||
56 水天一色
|
|
||||||
57 水中撈月
|
|
||||||
58 水火不容
|
|
||||||
59 水泛銀光
|
|
||||||
60 水光瀲灩
|
|
||||||
|
|
||||||
61 火冒三丈
|
|
||||||
62 火樹銀花
|
|
||||||
63 火上加油
|
|
||||||
64 火眼金睛
|
|
||||||
65 火急火燎
|
|
||||||
66 火燒眉毛
|
|
||||||
67 火中取栗
|
|
||||||
68 火光沖天
|
|
||||||
69 火傘高張
|
|
||||||
70 火爆脾氣
|
|
||||||
|
|
||||||
71 虎頭蛇尾
|
|
||||||
72 虎視眈眈
|
|
||||||
73 虎背熊腰
|
|
||||||
74 虎口拔牙
|
|
||||||
75 虎虎生風
|
|
||||||
76 虎落平陽
|
|
||||||
77 虎踞龍盤
|
|
||||||
78 虎將雄兵
|
|
||||||
79 虎穴龍潭
|
|
||||||
80 虎嘯風生
|
|
||||||
|
|
||||||
81 雪上加霜
|
|
||||||
82 雪中送炭
|
|
||||||
83 雪恥報仇
|
|
||||||
84 雪落無痕
|
|
||||||
85 雪泥鴻爪
|
|
||||||
86 雪擁藍關
|
|
||||||
87 雪山飛狐
|
|
||||||
88 雪過天晴
|
|
||||||
89 雪兆豐年
|
|
||||||
90 雪白晶瑩
|
|
||||||
|
|
||||||
91 風平浪靜
|
|
||||||
92 風雨如晦
|
|
||||||
93 風吹草動
|
|
||||||
94 風調雨順
|
|
||||||
95 風捲殘雲
|
|
||||||
96 風花雪月
|
|
||||||
97 風華絶代
|
|
||||||
98 風光旖旎
|
|
||||||
99 風馳電掣
|
|
||||||
100 風起雲湧
|
|
||||||
|
|
||||||
101 雲淡風輕
|
|
||||||
102 雲霧繚繞
|
|
||||||
103 雲消雲散
|
|
||||||
104 雲蒸霞蔚
|
|
||||||
105 雲集四方
|
|
||||||
106 雲開日出
|
|
||||||
107 雲程發軔
|
|
||||||
108 雲躍龍驤
|
|
||||||
109 雲深不知
|
|
||||||
110 雲飛雨散
|
|
||||||
|
|
||||||
111 明察秋毫
|
|
||||||
112 明爭暗鬥
|
|
||||||
113 明目張膽
|
|
||||||
114 明察暗訪
|
|
||||||
115 明心見性
|
|
||||||
116 明亮耀眼
|
|
||||||
117 明哲保身
|
|
||||||
118 明火執仗
|
|
||||||
119 明辨是非
|
|
||||||
120 明鏡高懸
|
|
||||||
|
|
||||||
121 虛懷若谷
|
|
||||||
122 虛與委蛇
|
|
||||||
123 虛張聲勢
|
|
||||||
124 虛實相生
|
|
||||||
125 虛名虛利
|
|
||||||
126 虛心學習
|
|
||||||
127 虛席以待
|
|
||||||
128 虛誇浮誇
|
|
||||||
129 虛堂懸鏡
|
|
||||||
130 虛言詐語
|
|
||||||
|
|
||||||
131 高瞻遠矚
|
|
||||||
132 高山流水
|
|
||||||
133 高談闊論
|
|
||||||
134 高風亮節
|
|
||||||
135 高朋滿座
|
|
||||||
136 高不可攀
|
|
||||||
137 高官厚祿
|
|
||||||
138 高屋建瓴
|
|
||||||
139 高視闊步
|
|
||||||
140 高枕無憂
|
|
||||||
|
|
||||||
141 安然無恙
|
|
||||||
142 安居樂業
|
|
||||||
143 安步當車
|
|
||||||
144 安然度日
|
|
||||||
145 安貧樂道
|
|
||||||
146 安身立命
|
|
||||||
147 安之若素
|
|
||||||
148 安土重遷
|
|
||||||
149 安然自得
|
|
||||||
150 安分守己
|
|
||||||
|
|
||||||
151 白日做夢
|
|
||||||
152 白璧無瑕
|
|
||||||
153 白駒過隙
|
|
||||||
154 白紙黑字
|
|
||||||
155 白雪皚皚
|
|
||||||
156 白頭偕老
|
|
||||||
157 白雲蒼狗
|
|
||||||
158 白衣天使
|
|
||||||
159 白手起家
|
|
||||||
160 白話連篇
|
|
||||||
|
|
||||||
161 金玉滿堂
|
|
||||||
162 金枝玉葉
|
|
||||||
163 金石為開
|
|
||||||
164 金榜題名
|
|
||||||
165 金聲玉振
|
|
||||||
166 金戈鐵馬
|
|
||||||
167 金光閃閃
|
|
||||||
168 金玉其外
|
|
||||||
169 金鼓齊鳴
|
|
||||||
170 金碧輝煌
|
|
||||||
|
|
||||||
171 石破天驚
|
|
||||||
172 石沉大海
|
|
||||||
173 石火電光
|
|
||||||
174 石破驚天
|
|
||||||
175 石壓草枯
|
|
||||||
176 石室金匱
|
|
||||||
177 石心鐵腸
|
|
||||||
178 石泉清冽
|
|
||||||
179 石橋流水
|
|
||||||
180 石室藏書
|
|
||||||
|
|
||||||
181 夜深人靜
|
|
||||||
182 夜闌人靜
|
|
||||||
183 夜以繼日
|
|
||||||
184 夜色迷離
|
|
||||||
185 夜幕降臨
|
|
||||||
186 夜雨對床
|
|
||||||
187 夜光如晝
|
|
||||||
188 夜半鐘聲
|
|
||||||
189 夜色朦朧
|
|
||||||
190 夜寂無聲
|
|
||||||
|
|
||||||
191 龍飛鳳舞
|
|
||||||
192 龍爭虎鬥
|
|
||||||
193 龍盤虎踞
|
|
||||||
194 龍馬精神
|
|
||||||
195 龍鳳呈祥
|
|
||||||
196 龍吟虎嘯
|
|
||||||
197 龍躍鳳鳴
|
|
||||||
198 龍行虎步
|
|
||||||
199 龍驤虎步
|
|
||||||
200 龍章鳳彩
|
|
||||||
@ -1,67 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <queue>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define sl static inline
|
|
||||||
const ll maxn = 100000+7, maxm=500000+7,inf=1e9+7;
|
|
||||||
ll n,m,p[maxn],maxp[maxn],minp[maxn],ans=-inf;
|
|
||||||
std::vector<std::vector<ll>> edg,redg;
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>m;
|
|
||||||
edg.resize(n+1);
|
|
||||||
redg=edg;
|
|
||||||
std::fill(maxp+1,maxp+1+n,-inf);
|
|
||||||
std::fill(minp+1,minp+1+n,inf);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>p[i];
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=m;i++){
|
|
||||||
ll x,y,z;
|
|
||||||
std::cin>>x>>y>>z;
|
|
||||||
if(z==1){
|
|
||||||
edg[x].emplace_back(y);
|
|
||||||
redg[y].emplace_back(x);
|
|
||||||
}else{
|
|
||||||
edg[x].emplace_back(y);
|
|
||||||
edg[y].emplace_back(x);
|
|
||||||
redg[x].emplace_back(y);
|
|
||||||
redg[y].emplace_back(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::queue<ll> q;
|
|
||||||
q.emplace(n);
|
|
||||||
maxp[n]=p[n];
|
|
||||||
while(q.size()){
|
|
||||||
ll u=q.front();
|
|
||||||
q.pop();
|
|
||||||
for(ll v:redg[u]){
|
|
||||||
if(maxp[u]<=maxp[v]){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
maxp[v]=std::max(p[v],maxp[u]);
|
|
||||||
q.emplace(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
minp[1]=p[1];
|
|
||||||
q.emplace(1);
|
|
||||||
while(q.size()){
|
|
||||||
ll u=q.front();
|
|
||||||
q.pop();
|
|
||||||
ans=std::max(maxp[u]-minp[u],ans);
|
|
||||||
for(ll v:edg[u]){
|
|
||||||
if(minp[u]>=minp[v]){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
minp[v]=std::min(p[v],minp[u]);
|
|
||||||
q.emplace(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<ans<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,116 +0,0 @@
|
|||||||
#include <bitset>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <queue>
|
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define sl static inline
|
|
||||||
#define printf
|
|
||||||
const ll m=10;
|
|
||||||
ll n,k;
|
|
||||||
std::vector<std::vector<char>> v;
|
|
||||||
std::vector<std::bitset<m+1>> vis;
|
|
||||||
const ll dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
|
|
||||||
std::vector<std::pair<ll, ll>> mb;
|
|
||||||
|
|
||||||
sl bool find(ll i,ll j){
|
|
||||||
printf("--START i=%lld, j=%lld\n",i,j);
|
|
||||||
mb.clear();
|
|
||||||
ll num=1;
|
|
||||||
std::queue<std::pair<ll, ll>> q;
|
|
||||||
q.emplace(i,j);
|
|
||||||
vis[i][j]=true;
|
|
||||||
char c=v[i][j];
|
|
||||||
while(q.size()){
|
|
||||||
auto[x,y]=q.front();
|
|
||||||
q.pop();
|
|
||||||
for(ll k=0;k<4;k++){
|
|
||||||
ll nx=x+dir[k][0],ny=y+dir[k][1];
|
|
||||||
if(nx<1||nx>n||ny<1||ny>m||c!=v[nx][ny]||vis[nx][ny])continue;
|
|
||||||
vis[nx][ny]=true;
|
|
||||||
num++;
|
|
||||||
q.emplace(nx,ny);
|
|
||||||
}
|
|
||||||
if(num>=k){
|
|
||||||
v[x][y]='0';
|
|
||||||
printf("find x=%lld, y=%lld\n",x,y);
|
|
||||||
}else{
|
|
||||||
mb.emplace_back(x,y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(num>=k){
|
|
||||||
for(auto[x,y]:mb){
|
|
||||||
v[x][y]='0';
|
|
||||||
printf("find x=%lld, y=%lld\n",x,y);
|
|
||||||
}
|
|
||||||
mb.clear();
|
|
||||||
}
|
|
||||||
return num>=k;
|
|
||||||
}
|
|
||||||
|
|
||||||
sl void pm(){
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
for(ll j=1;j<=m;j++){
|
|
||||||
printf("%c",v[i][j]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
printf("---\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
sl void move(){
|
|
||||||
for(ll j=1;j<=m;j++){
|
|
||||||
ll l=-1;
|
|
||||||
for(ll i=n;i>=1;i--){
|
|
||||||
if(v[i][j]=='0'&&l==-1)l=i;
|
|
||||||
else if(l!=-1&&v[i][j]!='0'){
|
|
||||||
v[l][j]=v[i][j];
|
|
||||||
v[i][j]='0';
|
|
||||||
l--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sl bool check(){
|
|
||||||
vis.clear();
|
|
||||||
vis.resize(n+1);
|
|
||||||
bool ret=false;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
for(ll j=1;j<=m;j++){
|
|
||||||
if(v[i][j]!='0'){
|
|
||||||
if(find(i,j)){
|
|
||||||
pm();
|
|
||||||
pm();
|
|
||||||
ret=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
move();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>k;
|
|
||||||
v.resize(n+1,std::vector<char>(m+1));
|
|
||||||
vis.resize(n+1);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
for(ll j=1;j<=m;j++){
|
|
||||||
std::cin>>v[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (check());
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
for(ll j=1;j<=m;j++){
|
|
||||||
std::cout<<v[i][j];
|
|
||||||
}
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
ll n,d;
|
|
||||||
std::vector<std::vector<ll>> m;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>d;
|
|
||||||
m.resize(n+1,std::vector<ll>(n+1));
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
for(ll j=1;j<=n;j++){
|
|
||||||
std::cin>>m[i][j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define printf
|
|
||||||
const ll inf=1e9+7;
|
|
||||||
ll n,m,ans=inf;
|
|
||||||
std::vector<ll> a,b,aa,bb,mm,lmax,rmin;
|
|
||||||
|
|
||||||
#define pa(a)do {\
|
|
||||||
printf(#a"[]: ");\
|
|
||||||
for(ll i=1;i<=n;i++){\
|
|
||||||
printf("%lld ",a[i]);\
|
|
||||||
}\
|
|
||||||
printf("\n");\
|
|
||||||
}while(0)
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n>>m;
|
|
||||||
a.resize(n+1);
|
|
||||||
aa.resize(n+1);
|
|
||||||
b.resize(n+1);
|
|
||||||
bb.resize(n+2);
|
|
||||||
mm.resize(n+2,inf);
|
|
||||||
lmax.resize(n+2);
|
|
||||||
rmin.resize(n+2,inf);
|
|
||||||
|
|
||||||
for(ll i=1;i<=n;i++)std::cin>>a[i];
|
|
||||||
for(ll i=1;i<=n;i++)std::cin>>b[i];
|
|
||||||
|
|
||||||
for(ll i=n;i>=1;i--){
|
|
||||||
mm[i]=std::min(mm[i+1],a[i]);
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
lmax[i]=std::max(lmax[i-1],b[i]);
|
|
||||||
}
|
|
||||||
for(ll i=n;i>=1;i--){
|
|
||||||
rmin[i]=std::min(rmin[i+1],b[i]);
|
|
||||||
}
|
|
||||||
ll nmin=inf;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
nmin=std::min(nmin,b[i]);
|
|
||||||
aa[i]=std::min(nmin,mm[i+1]);
|
|
||||||
}
|
|
||||||
mm.assign(n+2,-inf);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
mm[i]=std::max(mm[i-1],a[i]);
|
|
||||||
}
|
|
||||||
ll nmax=-inf;
|
|
||||||
for(ll i=n;i>=1;i--){
|
|
||||||
nmax=std::max(nmax,b[i]);
|
|
||||||
bb[i]=std::max(nmax,mm[i-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ll i=0;i<=m;i++){
|
|
||||||
ans=std::min(ans,std::max(bb[n-(m-i)+1],lmax[i])-std::min(aa[i],rmin[n-(m-i)+1]));
|
|
||||||
}
|
|
||||||
pa(aa);
|
|
||||||
pa(bb);
|
|
||||||
pa(lmax);
|
|
||||||
pa(rmin);
|
|
||||||
std::cout<<ans<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,77 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define printf
|
|
||||||
const ll inf=1e9+7;
|
|
||||||
ll n,anq,ans=-inf,ansi;
|
|
||||||
std::map<ll,ll> m;
|
|
||||||
std::vector<ll> l,r,w,a,b,t,xr,eq,nq;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n;
|
|
||||||
l.resize(n+1);r.resize(n+1);w.resize(n+1);a.resize(n+1);b.resize(n+1);t.resize(n+1);
|
|
||||||
m[0]=0;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>t[i];
|
|
||||||
if(t[i]==1){
|
|
||||||
std::cin>>l[i]>>r[i]>>w[i];
|
|
||||||
m[l[i]-1]=m[l[i]]=m[l[i]+1]=m[r[i]-1]=m[r[i]]=m[r[i]+1]=m[r[i]+2]=0;
|
|
||||||
}else if(t[i]==2){
|
|
||||||
std::cin>>a[i]>>w[i];
|
|
||||||
m[a[i]-1]=m[a[i]]=m[a[i]+1]=0;
|
|
||||||
}else{
|
|
||||||
std::cin>>b[i]>>w[i];
|
|
||||||
m[b[i]-1]=m[b[i]]=m[b[i]+1]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ll idx=1;
|
|
||||||
for(auto&[k,v]:m){
|
|
||||||
v=idx++;
|
|
||||||
printf("k=%lld, v=%lld\n",k,v);
|
|
||||||
}
|
|
||||||
xr.resize(idx+1);
|
|
||||||
eq.resize(idx+1);nq.resize(idx+1);
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
if(t[i]==1){
|
|
||||||
ll nl=m[l[i]],nr=m[r[i]];
|
|
||||||
xr[nl]^=w[i];
|
|
||||||
xr[nr+1]^=w[i];
|
|
||||||
}else if(t[i]==2){
|
|
||||||
ll na=m[a[i]];
|
|
||||||
eq[na]^=w[i];
|
|
||||||
}else{
|
|
||||||
ll nb=m[b[i]];
|
|
||||||
nq[nb]^=w[i];
|
|
||||||
anq^=w[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=idx;i++){
|
|
||||||
xr[i]^=xr[i-1];
|
|
||||||
}
|
|
||||||
auto rp=m.begin();
|
|
||||||
for(ll i=1;i<idx;i++){
|
|
||||||
ll nans=0;
|
|
||||||
nans^=eq[i];
|
|
||||||
nans^=xr[i];
|
|
||||||
nans^=anq^nq[i];
|
|
||||||
if(nans==ans && std::abs(rp->first)<std::abs(ansi)){
|
|
||||||
ansi=rp->first;
|
|
||||||
ans=nans;
|
|
||||||
}
|
|
||||||
if(nans>ans){
|
|
||||||
ansi=rp->first;
|
|
||||||
ans=nans;
|
|
||||||
}
|
|
||||||
rp++;
|
|
||||||
}
|
|
||||||
std::cout<<ans<<" "<<ansi<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define printf
|
|
||||||
ll n,ans;
|
|
||||||
std::vector<ll> a;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n;
|
|
||||||
a.resize(n);
|
|
||||||
for(ll i=0;i<n;i++)std::cin>>a[i];
|
|
||||||
|
|
||||||
std::sort(a.begin(),a.end());
|
|
||||||
a.erase(std::unique(a.begin(),a.end()),a.end());
|
|
||||||
n=a.end()-a.begin();
|
|
||||||
std::reverse(a.begin(),a.end());
|
|
||||||
|
|
||||||
for(auto i:a){
|
|
||||||
printf("%lld ",i);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
for(ll k=0;k<n;k++){
|
|
||||||
if(a[k]<=ans)break;
|
|
||||||
for(ll i=0;i<n;i++){
|
|
||||||
for(ll j=0;j<n;j++){
|
|
||||||
if(i==j||i==k||j==k)continue;
|
|
||||||
if(a[i]+a[j]<a[k])break;
|
|
||||||
if(ll nxt=(a[i]+a[j])%a[k];nxt>=ans){
|
|
||||||
ans=nxt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out:;
|
|
||||||
std::cout<<ans<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <set>
|
|
||||||
#include <string>
|
|
||||||
using ll = int64_t;
|
|
||||||
|
|
||||||
const ll b=233,p=1e9+7;
|
|
||||||
|
|
||||||
ll n;
|
|
||||||
std::string tmp;
|
|
||||||
std::set<ll> s;
|
|
||||||
|
|
||||||
static inline ll strhash(std::string &s){
|
|
||||||
ll res=0;
|
|
||||||
for(ll i=0;i<s.size();i++){
|
|
||||||
res=(res*b+s[i]-'0')%p;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>n;
|
|
||||||
for(ll i=1;i<=n;i++){
|
|
||||||
std::cin>>tmp;
|
|
||||||
s.emplace(strhash(tmp));
|
|
||||||
}
|
|
||||||
std::cout<<s.size()<<"\n";
|
|
||||||
}
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <istream>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
using ll = int64_t;
|
|
||||||
#define printf
|
|
||||||
#define sl static inline
|
|
||||||
|
|
||||||
const ll b=233,p=1e9+7;
|
|
||||||
std::string s1,s2;
|
|
||||||
ll n1,n2,h2;
|
|
||||||
std::vector<ll> v1,bp,v2,v2r;
|
|
||||||
|
|
||||||
sl ll strhash(std::string&s){
|
|
||||||
ll res=0;
|
|
||||||
for(ll i=0;i<s.size();i++){
|
|
||||||
res=(res*b+s[i])%p;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
std::iostream::sync_with_stdio(false);
|
|
||||||
std::cin.tie(nullptr);
|
|
||||||
|
|
||||||
std::cin>>s1>>s2;
|
|
||||||
h2=strhash(s2);
|
|
||||||
n1=s1.size(),n2=s2.size();
|
|
||||||
s1=' '+s1;s2=' '+s2;
|
|
||||||
v1.resize(s1.size());
|
|
||||||
v2.resize(s2.size());
|
|
||||||
v2r.resize(s2.size()+1);
|
|
||||||
bp.resize(std::max(s1.size(),s2.size()));
|
|
||||||
bp[0]=1;
|
|
||||||
for(ll i=1;i<bp.size();i++){
|
|
||||||
bp[i]=(bp[i-1]*b)%p;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ll i=1;i<=n1;i++){
|
|
||||||
v1[i]=(v1[i-1]*b+s1[i])%p;
|
|
||||||
if(ll s=i-n2+1;s>=1){
|
|
||||||
ll h1=(v1[i]-v1[s-1]*bp[n2]%p+p)%p;
|
|
||||||
printf("v1=%lld, h1=%lld, h2=%lld\n",v1[i],h1,h2);
|
|
||||||
if(h1==h2){
|
|
||||||
std::cout<<s<<"\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=n2;i++){
|
|
||||||
v2[i]=(v2[i-1]*b+s2[i])%p;
|
|
||||||
}
|
|
||||||
for(ll i=n2;i>=1;i--){
|
|
||||||
v2r[i]=(v2r[i+1]*b+s2[i])%p;
|
|
||||||
}
|
|
||||||
for(ll i=1;i<=n2;i++){
|
|
||||||
ll l=1,r=i/2,ans=0,mid;
|
|
||||||
while(l<=r){
|
|
||||||
mid=(l+r)/2;
|
|
||||||
ll h1=v2[mid];
|
|
||||||
// ll h2=(v2[i]-v2[i-mid]*bp[mid]%p+p)%p;
|
|
||||||
ll h2=(v2r[i-mid+1]-v2r[i+1]*bp[mid]%p+p)%p;
|
|
||||||
printf("i=%lld, l=%lld, r=%lld, mid=%lld, h1=%lld, h2=%lld\n",i,l,r,mid,h1,h2);
|
|
||||||
if(h1==h2){
|
|
||||||
ans=mid;
|
|
||||||
l=mid+1;
|
|
||||||
}else{
|
|
||||||
r=mid-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout<<ans<<" ";
|
|
||||||
}
|
|
||||||
std::cout<<"\n";
|
|
||||||
}
|
|
||||||
38
src/2/P3370.cpp
Normal file
38
src/2/P3370.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using ull= unsigned long long;
|
||||||
|
|
||||||
|
ull base = 131;
|
||||||
|
ull a[10010];
|
||||||
|
char s[10010];
|
||||||
|
int n, ans = 1;
|
||||||
|
int prime = 233317;
|
||||||
|
const ull mod = 212370440130137957ll;
|
||||||
|
|
||||||
|
ull mhash(char *s) {
|
||||||
|
int len = strlen(s);
|
||||||
|
ull ans = 0;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
ans = (ans * base + (ull)s[i]) % mod + prime;
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
iostream::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);
|
||||||
|
cin >> n;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> s;
|
||||||
|
a[i] = mhash(s);
|
||||||
|
}
|
||||||
|
sort(a + 1, a + n + 1);
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
if (a[i] != a[i + 1])
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
cout << ans << '\n';
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user