[C++] AtCoder Beginner Contest 181 B번 Trapezoid Sum

AtCoder Beginner Contest 181 B번 Trapezoid Sum

문제

https://atcoder.jp/contests/abc181/tasks/abc181_b abc181_b

풀이

Trapezoid은 사다리꼴이라는 이야긴데 왜 사다리꼴인지는 모르겠다.

n까지의 모든 i에 대해 A_i부터 B_i 까지의 모든 합을 더하면 되는 문제이다.

코드

#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc181/tasks/abc181_b
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i,n){
        ll s,e;
        cin >> s >> e;
        ans += (e * (e+1))/2 - (s*(s-1))/2;
    }
    cout << ans;
 
    return 0;
}