結果

問題 No.1194 Replace
ユーザー auauaauaua
提出日時 2020-08-22 16:58:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 991 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 176,884 KB
実行使用メモリ 31,464 KB
最終ジャッジ日時 2024-04-23 11:05:04
合計ジャッジ時間 12,337 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 640 ms
31,280 KB
testcase_08 AC 671 ms
31,332 KB
testcase_09 AC 619 ms
31,360 KB
testcase_10 AC 652 ms
31,428 KB
testcase_11 AC 648 ms
31,464 KB
testcase_12 AC 669 ms
31,360 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=998244353;
const int MAX=300010;


signed main(){
    ll n,m;cin>>n>>m;
    vector<pll>q(m);
    map<ll,ll>ma;
    rep(i,m){
        ll b,c;cin>>b>>c;
        ma[b]=b;
        ma[c]=c;
        q[i]=mp(c,b);
    }
    sort(rall(q));
    rep(i,m){
        ll b=q[i].second;
        ll c=q[i].first;
        ma[b]=max(ma[b],ma[c]);
    }
    ll ans=n*(n+1)/2;
    for(auto e:ma){
        ll b=e.fi;
        ll c=e.se;
        ans+=(c-b);
    }
    cout<<ans<<endl;
}
0