結果
| 問題 | 
                            No.1194 Replace
                             | 
                    
| コンテスト | |
| ユーザー | 
                             auaua
                         | 
                    
| 提出日時 | 2020-08-22 16:58:36 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 991 bytes | 
| コンパイル時間 | 1,844 ms | 
| コンパイル使用メモリ | 181,160 KB | 
| 実行使用メモリ | 31,360 KB | 
| 最終ジャッジ日時 | 2024-10-15 11:00:29 | 
| 合計ジャッジ時間 | 14,616 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 WA * 21 | 
ソースコード
#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;
}
            
            
            
        
            
auaua