首页 > 其他分享 >Luogu P2412 查单词

Luogu P2412 查单词

时间:2022-10-25 14:00:11浏览次数:65  
标签:P2412 int Luogu tt tree 单词 build ans include


题目链接:​​传送门​

做完这个题感觉我是个沙雕
在越做越麻烦的道路上一去不复返
我真傻,
真的
(会有大量冗余变量)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define

using namespace std;
typedef long long ll;
struct node {
int l, r, mx;
}tree[A];
int n, m, w[A], a, b;
struct word {
string s;
int id;
friend bool operator < (const word a, const word b) {
return a.s > b.s;
}
}e[A], t[A], tt[A], ttt[A];
void build(int k, int l, int r) {
tree[k].l = l; tree[k].r = r;
if (l == r) {
tree[k].mx = w[l];
return;
}
int m = (l + r) >> 1;
build(k << 1, l, m);
build(k << 1 | 1, m + 1, r);
tree[k].mx = min(tree[k << 1].mx, tree[k << 1 | 1].mx);
}
int ask(int k, int l, int r) {
if (tree[k].l >= l and tree[k].r <= r) return tree[k].mx;
int m = (tree[k].l + tree[k].r) >> 1, ans = 0x3f3f3f3f;
if (l <= m) ans = min(ans, ask(k << 1 , l, r));
if (r > m) ans = min(ans, ask(k << 1 | 1, l, r));
return ans;
}

int main(int argc, char const *argv[]) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> e[i].s; tt[i].s = e[i].s; tt[i].id = i; ttt[i] = tt[i];
transform(e[i].s.begin(), e[i].s.end(), e[i].s.begin(), ::tolower);
e[i].id = i, t[i] = e[i];
}
sort(t + 1, t + n + 1);
for (int i = 1; i <= n; i++) tt[i] = ttt[t[i].id];
for (int i = 1; i <= n; i++) w[t[i].id] = i;
build(1, 1, n);
while (m--) {
cin >> a >> b;
cout << tt[ask(1, a, b)].s << endl;
}
}


标签:P2412,int,Luogu,tt,tree,单词,build,ans,include
From: https://blog.51cto.com/lyle/5794684

相关文章

  • LOJ #2012. 「SCOI2016」背单词
    题目链接:​​传送门​​显然第一个情况和第二个情况不如第三个更优并且他们可以避免,所以尽量构造第三种情况将每个字符倒着插入trie树,因为先放后面的字符串是更优的然后......
  • 20221025 英文单词
    1、arbitrate仲裁;公断  2、aisle 3、accounting  4、admit  5、admittance进入权   6、applause  7、applaud  8、appetizer ......
  • 【luogu ARC106E】Medals(二分)(高维前缀和)
    Medals题目链接:luoguARC106E题目大意有n个第i个人的出现规律是对于所有2aik+1~2ai(k+1)的区间,2aik+1~2aik+ai会出现,另一部分则会不见。每个时间点你可以选择一......
  • 【luogu AGC035E】Develop(分类讨论)(DP)
    Develop题目链接:luoguAGC035E题目大意一开始有-1e18~1e18的所有整数,然后你每次操作可以在1~N中选一个还在的数x,擦掉他,然后查看x-2,x+K,如果没有就把数加上。然后......
  • luogu P8275 [USACO22OPEN] 262144 Revisited P
    题面传送门这里有个sb写这道题写了一下午。首先来考虑一段子段上的答案,显然答案有一个区间,设最大值为\(E\),则最小值一定在\([E,E+\logn]\)之间。我们考虑按照最大值分......
  • 20221024 英文单词
    Iscoffeegoodorbadforyourhealth?https://www.hsph.harvard.edu/news/hsph-in-the-news/is-coffee-good-or-bad-for-your-health/1、teamwork  2、virtually......
  • 学习笔记:python统计单词数
    python学习问题:统计文章中某个单词出现的次数英文由空格分割开每个单词,所以我采用以下方法:a=str(input("请输入一段英文:"))a=a.lower()b=a.split("")c=str......
  • java统计一个文本文件英文单词
    packagetest;importjava.io.*;importjava.util.*;publicclasswordCount2{publicstaticvoidmain(String[]args)throwsIOException{Filefile=n......
  • luogu P8585 球状精灵的传说 题解
    题目大意给定\(n\)个精灵的三维幅度\(\{r_{1,i},r_{2,i},r_{3,i}\}\),任意两个精灵若在三个幅度中有两个相同(这里可以乱序)则可以将剩下的一位相加组合起来。组合过的精......
  • 【Python】第3章-18 统计一行文本的单词个数
    随机输入一个字符串,把最左边的10个不重复的英文字母(不区分大小写)挑选出来。如没有10个英文字母,显示信息“notfound”输入格式:在一行中输入字符串输出格式:在一行中......