[ABC221E] LEQ 题解
1.AT_abc333_e [ABC333E] Takahashi Quest 题解2.[ABC265F] Manhattan Cafe 题解3.[ABC271E] Subsequence Path 题解4.[ABC273D] LRUD Instructions 题解5.P8085 [COCI2011-2012#4] KRIPTOGRAM 题解6.[ABC238F] Two Exams 题解7.[ABC217F] Make Pair 题解8.[ABC219F] Cleaning Robot 题解9.[ABC219E] Moat 题解10.[ABC221D] Online games 题解
11.[ABC221E] LEQ 题解
12.[ABC223E] Placing Rectangles 题解13.[ABC211D] Number of Shortest paths 题解14.[ABC211F] Rectilinear Polygons 题解15.[ABC223F] Parenthesis Checking 题解16.CF154C Double Profiles 题解17.[ABC208D] Shortest Path Queries 2 题解18.[ABC212E] Safety Journey 题解19.[ABC229E] Graph Destruction 题解20.[ABC240E] Ranges on Tree 题解21.[ABC261E] Many Operations 题解22.P10842 【MX-J2-T3】Piggy and Trees 题解[ABC221E] LEQ 题解
思路解析
很有思维量的一道题。首先根据题目要求发现,新求的子序列只跟子序列的头尾有关,而在确定头尾之后中间的元素选或不选没有任何关系。也就是确定新子序列的头尾下标分别为
接下来我们思考,根据题目要求,上方的
那么接下来就很轻松了,由于上方的
注意:由于有取模和乘方,所以需要使用逆元和快速幂求解。
时间复杂度:需要遍历每个下标,都需要一次区间查询和单点修改,复杂度为
code
//ABC211E
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3e5 + 10;
const ll mod = 998244353;
int n, m;
ll a[N], c[N], b[N];
map<ll, int> rk;
ll ksm(ll a, ll b, ll p) {
ll ans = 1;
while(b) {
if(b & 1) {
ans = ans * a % p;
}
a = a * a % p;
b >>= 1;
}
return ans;
}
ll niyuan(ll a, ll p) {
return ksm(a, p - 2, p);
}
void add(ll x, ll y) {
for(; x <= n; x += (x & -x)) {
c[x] = (c[x] + y) % mod;
}
}
ll ask(ll x) {
ll sum = 0;
for(; x > 0; x -= (x & -x)) {
sum = (sum + c[x]) % mod;
}
return sum;
}
int main() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + n + 1);
for(int i = 1; i <= n; i++) {
rk[b[i]] = i;
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
ans = (ans + (ksm(2, i, mod) * ask(rk[a[i]])) % mod) % mod;
add(rk[a[i]], ksm(niyuan(2, mod), i + 1, mod));
}
cout << ans;
return 0;
}
合集:
题解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】