提出 #71853327


ソースコード 拡げる

#if !__INCLUDE_LEVEL__
#include __FILE__
ll op(ll a,ll b){
  return a+b;
}
ll e(){
  return 0;
}

void solve() {
  ll N,M;
  cin>>N>>M;
  vl A(N),B(M);
  //fenwick_tree<ll> fw(M);
  rep(i,N)cin>>A[i];
  rep(i,M)cin>>B[i];
  sort(all(B));
  segtree<ll,op,e> seg(B);
  ll ans=0;
  rep(i,N){
    ll pla=lower_bound(all(B),A[i])-B.begin();
    ll sum=0;
    sum+=A[i]*pla-seg.prod(0,(int)pla);
    sum%=998244353;
    sum+=seg.prod((int)pla,M)-A[i]*(M-pla);
    sum%=998244353;
    ans+=sum;
    ans%=998244353;
  }
  cout<<ans<<el;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)solve();
}

#else
#include <bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
//using mint=modint998244353;

  
// 関数テンプレート
template<typename T> bool chmax(T &m, const T q) {
    if (m < q) {m = q; return true;} else return false; }

template<typename T> bool chmin(T &m,const T q){
    if(m>q){m=q;return true;}else return false;
}
template<typename T>
bool grid_inside(const T h, const T w, const T &m, const T &n) {
    return (m >= 0 && m < h && n >= 0 && n < w);
}
// ループマクロ
#define rep(i,r) for(int i=0;(r)>i;i++)
#define REP(i,l,r) for(int i=(l);i<(r);i++)
#define rrep(i,N) for(int i=(N)-1;i>=0;i--)
#define RREP(i,r,N) for(int i=(N)-1;i>=r;i--)

// コンテナショートカット
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el '\n'
#define spa " "
#define pb push_back

// YES/NO 出力
#define Yes cout<<"Yes"<<el
#define No cout<<"No"<<el
#define YES cout<<"YES"<<el
#define NO cout<<"NO"<<el
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

// 型エイリアス
using ll=long long;
using ull=unsigned long long;
using pqgi=priority_queue<int, vector<int>, greater<int>>;
using pqgl=priority_queue<long long, vector<long long>, greater<long long>>;
using pqgpl=priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>>;
using pqgptpl=priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>>;
using pqi=priority_queue<int>;
using pii=pair<int, int>;
using tpi=tuple<int,int,int>;
using tpl=tuple<ll,ll,ll>;
using pll=pair<long long, long long>;
using vs=vector<string>;
using vi=vector<int>;
using vb=vector<bool>;
using vl=vector<long long>;
using vc=vector<char>;
using vvi=vector<vector<int>>;
using vvl=vector<vector<long long>>;
using vvc=vector<vector<char>>;
using vvb=vector<vector<bool>>;
using vvs=vector<vector<string>>;
using vpii=vector<pii>;
using vpll=vector<pll>;
using vvpii=vector<vector<pii>>;
using vvpll=vector<vector<pll>>;
using vtiii=vector<tuple<int, int, int>>;

// 定数
const long long INF=1e18;
const int mod=1e9+7;
//const int mod=998244353;
const int MAX=1e5+10;
const int MIN=-1e9;
const vpii dir={{1,0},{-1,0},{0,1},{0,-1}};
#endif


提出情報

提出日時
問題 D - Sum of Differences
ユーザ yasaikeikaku
言語 C++23 (GCC 15.2.0)
得点 400
コード長 3183 Byte
結果 AC
実行時間 138 ms
メモリ 16272 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 32
セット名 テストケース
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 2 ms 3564 KiB
00-sample-02.txt AC 1 ms 3440 KiB
01-01.txt AC 3 ms 3776 KiB
01-02.txt AC 2 ms 3856 KiB
01-03.txt AC 2 ms 3840 KiB
01-04.txt AC 2 ms 3776 KiB
01-05.txt AC 3 ms 3776 KiB
01-06.txt AC 2 ms 3896 KiB
01-07.txt AC 3 ms 3684 KiB
01-08.txt AC 3 ms 3696 KiB
01-09.txt AC 3 ms 3908 KiB
01-10.txt AC 2 ms 3840 KiB
01-11.txt AC 2 ms 3896 KiB
01-12.txt AC 2 ms 3864 KiB
01-13.txt AC 2 ms 3776 KiB
01-14.txt AC 3 ms 3696 KiB
01-15.txt AC 1 ms 3652 KiB
01-16.txt AC 1 ms 3640 KiB
01-17.txt AC 93 ms 15044 KiB
01-18.txt AC 111 ms 11080 KiB
01-19.txt AC 38 ms 13852 KiB
01-20.txt AC 16 ms 5720 KiB
01-21.txt AC 138 ms 16196 KiB
01-22.txt AC 65 ms 16084 KiB
01-23.txt AC 65 ms 16196 KiB
01-24.txt AC 84 ms 16192 KiB
01-25.txt AC 94 ms 16272 KiB
01-26.txt AC 39 ms 16140 KiB
01-27.txt AC 39 ms 10836 KiB
01-28.txt AC 44 ms 11040 KiB
01-29.txt AC 42 ms 10820 KiB
01-30.txt AC 94 ms 15188 KiB