Submission #51471326
Source Code Expand
// LUOGU_RID: 151826033
// Author: gsczl71
// Copyright (c) 2024 gsczl71 All rights reserved.
// Problem: E - LEQ
// Contest: AtCoder - AtCoder Beginner Contest 221
// URL: https://atcoder.jp/contests/abc221/tasks/abc221_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Date: 2024-03-19 16:33:46
// #pragma GCC optimize(2,3,"Ofast","inline")
#include<bits/stdc++.h>
#define ll long long
#define i128 __int128
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fs first
#define sc second
#define x0 _x0_
#define y1 _y1_
#define endl '\n'
#define re register
#define pb push_back
#define vi vector<int>
#define pq priority_queue
#define mem(a,x) memset((a),(x),sizeof(a))
#define debug puts("AK IOI")
#define sz(s) (int)(s.size())
#define all(a) a.begin(),a.end()
#define rd(l,r) (myrand()%(r-l+1)+l)
#define print(x) {cout<<x<<endl;return;}
#define ctn(e) if(e) continue
#define brk(e) if(e) break
#define rt(e) if(e) return
#define ll_(e) (1ll*(e))
#define For(x,y,z) for(int x = y;x <= z;x++)
#define For_(x,y,z) for(int x = y;x <= z;x--)
#define lowbit(x) (x&(-x))
using namespace std;
#define int long long
// const int mod = 1e9+7;
const int mod = 998244353;
mt19937 myrand(time(0));
const int inf = 0x3f3f3f3f,N = 3e5+5,M = 1e6+5,K = 3000+5;
const long long linf = 0x3f3f3f3f3f3f3f3f;
int n,a[N],b[N],m;
int res=0;
int t[N];
int ksm(int a,int b){
int res=1;
while(b){
if(b&1) {res *= a;res %= mod;}
a=a*a,a%=mod;
b>>=1;
} return res;
}void modify(int x,int v){
for(int i = x;i <= n;i += lowbit(i)) t[i] = (t[i] + v) % mod;
}int query(int x){
int res=0;
for(int i = x;i >= 1;i -= lowbit(i)) res = (res + t[i]) % mod;
return res;
}
void solve(){
cin>>n;For(i,1,n)b[i]=((cin>>a[i]),a[i]);
sort(b+1,b+1+n);
m=unique(b+1,b+1+n)-b-1;
For(i,1,n) a[i]=lower_bound(b+1,b+1+m,a[i])-b;
For(i,1,n) {
res += query(a[i]) * ksm(2,i-1) % mod;
res %= mod;
modify(a[i],ksm((mod+1>>1),i));
}cout<<res<<endl;
}
signed main(){
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T=1;
// cin >> T;
For(_,1,T) solve();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - LEQ |
| User |
Expert_Dream |
| Language |
C++ 17 (gcc 12.2) |
| Score |
500 |
| Code Size |
2199 Byte |
| Status |
AC |
| Exec Time |
134 ms |
| Memory |
10644 KiB |
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:72:37: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
72 | modify(a[i],ksm((mod+1>>1),i));
| ~~~^~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
500 / 500 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt, example1.txt, example2.txt, example3.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, example0.txt, example1.txt, example2.txt, example3.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
5 ms |
3472 KiB |
| 001.txt |
AC |
1 ms |
3500 KiB |
| 002.txt |
AC |
134 ms |
10596 KiB |
| 003.txt |
AC |
133 ms |
10500 KiB |
| 004.txt |
AC |
132 ms |
10524 KiB |
| 005.txt |
AC |
133 ms |
10600 KiB |
| 006.txt |
AC |
79 ms |
8052 KiB |
| 007.txt |
AC |
85 ms |
8288 KiB |
| 008.txt |
AC |
11 ms |
4280 KiB |
| 009.txt |
AC |
84 ms |
8284 KiB |
| 010.txt |
AC |
88 ms |
10644 KiB |
| 011.txt |
AC |
89 ms |
10520 KiB |
| 012.txt |
AC |
88 ms |
10600 KiB |
| 013.txt |
AC |
88 ms |
10616 KiB |
| 014.txt |
AC |
88 ms |
10528 KiB |
| 015.txt |
AC |
88 ms |
10500 KiB |
| 016.txt |
AC |
79 ms |
8292 KiB |
| 017.txt |
AC |
95 ms |
8136 KiB |
| 018.txt |
AC |
95 ms |
8200 KiB |
| 019.txt |
AC |
80 ms |
8200 KiB |
| 020.txt |
AC |
85 ms |
8220 KiB |
| 021.txt |
AC |
84 ms |
8220 KiB |
| 022.txt |
AC |
103 ms |
8280 KiB |
| 023.txt |
AC |
86 ms |
8112 KiB |
| 024.txt |
AC |
86 ms |
8284 KiB |
| 025.txt |
AC |
87 ms |
10536 KiB |
| 026.txt |
AC |
86 ms |
10584 KiB |
| 027.txt |
AC |
133 ms |
10592 KiB |
| 028.txt |
AC |
133 ms |
10520 KiB |
| 029.txt |
AC |
134 ms |
10588 KiB |
| 030.txt |
AC |
90 ms |
10504 KiB |
| example0.txt |
AC |
1 ms |
3580 KiB |
| example1.txt |
AC |
1 ms |
3500 KiB |
| example2.txt |
AC |
1 ms |
3696 KiB |
| example3.txt |
AC |
1 ms |
3448 KiB |