今年最乐 __O__W__O__

· · 个人记录

省流:本来棕14天变成封禁1年了

个人认为上面那张是最乐的↑↑↑

高潮

尾声

附件

const int nmax = 3005; const long long neg = -4000000000000000000LL;

int n, m, q; long long k1, k2; long long u[nmax][nmax]; long long lft[nmax], rgt[nmax], val[nmax];

inline long long mx(long long a, long long b){ return a > b ? a : b; }

void row_dp(int x){ for(int j = 1; j <= m; j++) val[j] = u[x][j]; long long best = neg; for(int j = 1; j <= m; j++){ best = mx(best, val[j] - k2 j); lft[j] = best; } best = neg; for(int j = m; j >= 1; j--){ best = mx(best, val[j] + k2 j); rgt[j] = best; } for(int j = 1; j <= m; j++){ u[x][j] = mx(k2 j + lft[j], -k2 j + rgt[j]); } } void col_dp(int j){ for(int i = 1; i <= n; i++) val[i] = u[i][j]; long long best = neg; for(int i = 1; i <= n; i++){ best = mx(best, val[i] - k1 i); lft[i] = best; } best = neg; for(int i = n; i >= 1; i--){ best = mx(best, val[i] + k1 i); rgt[i] = best; } } unsigned long long pw(unsigned long long a, long long e){ unsigned long long res = 1, x = a; while(e){ if(e & 1) res = x; x = x; e >>= 1; } return res; }

signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> q >> k1 >> k2; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) u[i][j] = neg; for(int t = 1; t <= q; t++){ int x, y; long long w; cin >> x >> y >> w; u[x][y] = mx(u[x][y], w); } for(int i = 1; i <= n; i++) row_dp(i);

unsigned long long base = 131ULL;
unsigned long long step_row = pw(base, m);
static unsigned long long row_pow[nmax], col_pow[nmax];
row_pow[1] = 1ULL;
for(int i = 2; i <= n; i++) 
    row_pow[i] = row_pow[i - 1] * step_row;
col_pow[1] = base;
for(int j = 2; j <= m; j++) 
    col_pow[j] = col_pow[j - 1] * base;
unsigned long long ans = 0ULL;
for(int j = 1; j <= m; j++){
    col_dp(j);
    for(int i = 1; i <= n; i++){
        long long f = mx(k1 * i + lft[i], -k1 * i + rgt[i]);
        unsigned long long w = row_pow[i] * col_pow[j];
        unsigned long long add = (unsigned long long)((__int128)f * w);
        ans += add;
    }
}

cout << ans;
return 0;

}

- 多次修改的[T3](https://www.luogu.com.cn/problem/P13790)代码
- 第一次
```cpp
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const unsigned long long base = 1315423911ULL;
const unsigned long long mod1 = (1ULL << 61) - 1;
string s;
int n;
unsigned long long pw[1000005],h[1000005];
unsigned long long hashh(int l,int r){
    return h[r] - h[l-1] * pw[r-l+1];
}
bool check_hash(int l1,int r1,int l2,int r2){
    return hashh(l1,r1) == hashh(l2,r2);
}
bool check(int len){
    int l1 = 1,r1 = len;
    int l2 = n - len + 1,r2 = n;
    if(check_hash(l1,r1,l2,r2)) return true;
    int l = 1,r = len;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(check_hash(l1,mid,l2,l2 + mid - 1)){
            l = mid + 1;
        }else{
            r = mid - 1;
        }
    }
    int pos = l;
    if(pos > len) return false;
    return check_hash(l1 + pos,r1,l2 + pos,r2);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> s;
    n = s.size();
    s = " " + s;
    pw[0] = 1;
    for(int i = 1; i <= n; i++){
        pw[i] = pw[i-1] * base;
        h[i] = h[i-1] * base + s[i];
    }
    int ans = 0;
    for(int len = n-1; len >= 1; len--){
        if(check(len)){
            ans = len;
            break;
        }
    }
    cout << ans;
}

string s; int n; unsigned long long pw[N], h[N];

unsigned long long geth(int l,int r){ return h[r] - h[l - 1] * pw[r - l + 1]; }

bool eq(int l1,int r1,int l2,int r2){ return geth(l1,r1) == geth(l2,r2); }

bool check(int len){ int l1 = 1, r1 = len; int l2 = n - len + 1, r2 = n; if(eq(l1,r1,l2,r2)) return true;

int l = 1, r = len;
while(l <= r){
    int mid = (l + r) >> 1;
    if(eq(l1,l1 + mid - 1,l2,l2 + mid - 1)){
        l = mid + 1;
    }else{
        r = mid - 1;
    }
}
int pos = l;
if(pos > len) return false;
if(eq(l1 + pos,r1,l2 + pos,r2)) return true;
if(eq(l1 + pos - 1,r1,l2 + pos,r2 - 1)) return true;
return false;

}

signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> s; n = s.size(); s = " " + s; pw[0] = 1; for(int i = 1; i <= n; i++){ pw[i] = pw[i - 1] base; h[i] = h[i - 1] base + s[i]; } int ans = 0; for(int len = n - 1; len >= 1; len--){ if(check(len)){ ans = len; break; } } bool flag = true; for(int i = 1;i <= n;i++){ if(s[i] != 'a' && s[i] != 'b'){ flag = false; break; } } if(flag){ cout << ans + ans / 2; return 0; } cout << ans; }

- 第三次
```cpp
#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;
const unsigned long long base = 1315423911ULL;
string s;
int n;
unsigned long long pw[N],h[N];
int pos[3],pc;
unsigned long long geth(int l,int r){
    return h[r] - h[l - 1] * pw[r - l + 1];
}
bool eq(int l1,int r1,int l2,int r2){
    return geth(l1,r1) == geth(l2,r2);
}
void f(int a1,int a2,int b1,int b2,int off){
    if(pc > 2) return;
    if(eq(a1,a2,b1,b2)) return;
    if(a1 == a2){
        if(pc < 3) pos[pc++] = off;
        return;
    }
    int len = a2 - a1 + 1;
    int mid = len >> 1;
    f(a1,a1 + mid - 1,b1,b1 + mid - 1,off);
    if(pc > 2) return;
    f(a1 + mid,a2,b1 + mid,b2,off + mid);
}

bool check(int len){
    if(len == 0) return true;
    int l2 = n - len + 1;
    pc = 0;
    f(1,len,l2,n,1);
    if(pc == 0) return true;
    if(pc == 1) return true;
    if(pc >= 3) return false;
    int a = pos[0],b = pos[1];
    if(b - a != n - len) 
        return false;
    if(s[a] == s[l2 + b - 1]) 
        return true;
    if(s[b] == s[l2 + a - 1]) 
        return true;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> s;
    n = (int)s.size();
    s = " " + s;
    pw[0] = 1;
    for(int i = 1;i <= n;i++){
        pw[i] = pw[i - 1] * base;
        h[i] = h[i - 1] * base + (unsigned long long)(unsigned char)s[i];
    }
    int l = 0,r = n - 1,ans = 0;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(check(mid)){
            ans = mid;
            l = mid + 1;
        }else{
            r = mid - 1;
        }
    }
    cout << ans;
    return 0;
}

signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> s; n = s.size(); if(n <= 1){ cout << 0 ; return 0; } int ans = 0; for(int L = n - 1;L >= 1;L--){ if(ok_length(L)){ ans = L; break; } } cout << ans; return 0; }


**不难发现他有很明显的修改(#define LL long long 在第一次后就没了)**

![](https://cdn.luogu.com.cn/upload/image_hosting/mbjo9bzn.png)
![](https://cdn.luogu.com.cn/upload/image_hosting/mbjo9bzn.png)
###### 文中立场不代表作者立场,请理性看待,图一乐就好。