2025/7/21考试总结

· · 个人记录

一.考试情况

题目 分数
【模板】单调栈 100分
[USACO19DEC] Milk Pumping G 100分
套利 100分
汽车拉力比赛 100分
忠诚 100分
查单词 0分

总分:500分

二.题目总结

AC记录

链接 代码
【模板】单调栈 AC code
[USACO19DEC] Milk Pumping G AC code
套利 AC code
汽车拉力比赛 AC code
忠诚 AC code

三.死因总结

死因:此题没有判断大小写,导致全部测试点都WA了
思路:按照RMQ的做法,把max函数重载一下就好了(要忽略大小写)
细节:max函数返回值是原来的字符串

时间复杂度:O(nlogn)

代码:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int MAXH = 5e4 + 17;
const int INF  = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n,m;
string MAX(string x,string y){
    string a = x,b = y;
    for(int i = 0;i < x.size();i++)
        if(a[i] >= 'A' && a[i] <= 'Z')
            a[i] = a[i] + 32;
    for(int i = 0;i < y.size();i++)
        if(b[i] >= 'A' && b[i] <= 'Z')
            b[i] = b[i] + 32;
    if(a > b)
        return x;
    else
        return y;
}
string dp[MAXH][35];
int lg[MAXH];
int main(){
//  freopen("F.in","r",stdin);
//  freopen("F.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin >> n >> m;
    lg[0] = -1;
    for(int i = 1;i <= n;i++)
        cin >> dp[i][0],lg[i] = lg[i >> 1] + 1;
    for(int j = 1;(1 << j) <= n;j++){
        for(int i = 1;i + (1 << j) - 1 <= n;i++){
            dp[i][j] = MAX(dp[i][j-1],dp[i+(1<<j-1)][j-1]);
        }
    }
    while(m--){
        int l,r;
        cin >> l >> r;
        int len = r - l + 1;
        int j = lg[len];
        cout << MAX(dp[l][j],dp[r-(1<<j)+1][j]) << endl;
    }
    return 0;
}