답안 #1007594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007594 2024-06-25T08:39:25 Z vjudge1 Addk (eJOI21_addk) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX         100005

int nArr, numRot, numQuery;
int A[MAX];

int sum[MAX];

int lz[4 * MAX], st[4 * MAX];

void pushDown(int id, int l, int r){
    if (!lz[id]) return;
    int m = (l + r) >> 1;

    st[id << 1] += (m - l + 1) * lz[id];
    st[id << 1 | 1] += (r - m) * lz[id];
    lz[id << 1] += lz[id];
    lz[id << 1 | 1] += lz[id];

    lz[id] = 0;
}

void upd(int id, int l, int r, int u, int v, int val){
    if (u > r || v < l) return;
    if (u <= l && v >= r){
        st[id] += (r - l + 1) * val;
        lz[id] += val;
        return;
    }
    int m = (l + r) >> 1;
    pushDown(id, l, r);
    upd(id << 1, l, m, u, v, val);
    upd(id << 1 | 1, m + 1, r, u, v, val);
    st[id] = st[id << 1] + st[id << 1 | 1];
}

int query(int id, int l, int r, int u, int v){
    if (u > r || v < l) return 0;
    if (u <= l && v >= r) return st[id];
    int m = (l + r) >> 1;
    pushDown(id, l, r);
    int ql = query(id << 1, l, m, u, v);
    int qr = query(id << 1 | 1, m + 1, r, u, v);
    return (ql + qr);
}

void process(void){
    cin >> nArr >> numRot;
    for (int i = 1; i <= nArr; ++i) cin >> A[i], upd(1, 1, nArr, i, nArr, A[i]);

    cin >> numQuery;
    for (int i = 1; i <= numQuery; ++i){
        int cmd, l, r, m;
        cin >> cmd;
        if(cmd == 1){
            vector<int> pos(numRot), val;
            for(int&v : pos) cin >> v;
            for (int j = 1; j < numRot; ++j) val.push_back(A[pos[j]]);
            val.push_back(A[pos[0]]);
            for (int j = 0; j < numRot; ++j){
                upd(1, 1, nArr, pos[j], nArr, val[j] - A[pos[j]]);
                A[pos[j]] = val[j];
            }
        }
        else{
            cin >> l >> r >> m;
            cout << query(1, 1, nArr, l + m - 1, r) - query(1, 1, nArr, l - 1, r - m) << '\n';
        }
    }
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    freopen(name".inp", "r", stdin);
    freopen(name".out", "w", stdout);
    process();

}



#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX         100005

int nArr, numRot, numQuery;
int A[MAX];

int sum[MAX];

int lz[4 * MAX], st[4 * MAX];

void pushDown(int id, int l, int r){
    if (!lz[id]) return;
    int m = (l + r) >> 1;

    st[id << 1] += (m - l + 1) * lz[id];
    st[id << 1 | 1] += (r - m) * lz[id];
    lz[id << 1] += lz[id];
    lz[id << 1 | 1] += lz[id];

    lz[id] = 0;
}

void upd(int id, int l, int r, int u, int v, int val){
    if (u > r || v < l) return;
    if (u <= l && v >= r){
        st[id] += (r - l + 1) * val;
        lz[id] += val;
        return;
    }
    int m = (l + r) >> 1;
    pushDown(id, l, r);
    upd(id << 1, l, m, u, v, val);
    upd(id << 1 | 1, m + 1, r, u, v, val);
    st[id] = st[id << 1] + st[id << 1 | 1];
}

int query(int id, int l, int r, int u, int v){
    if (u > r || v < l) return 0;
    if (u <= l && v >= r) return st[id];
    int m = (l + r) >> 1;
    pushDown(id, l, r);
    int ql = query(id << 1, l, m, u, v);
    int qr = query(id << 1 | 1, m + 1, r, u, v);
    return (ql + qr);
}

void process(void){
    cin >> nArr >> numRot;
    for (int i = 1; i <= nArr; ++i) cin >> A[i], upd(1, 1, nArr, i, nArr, A[i]);

    cin >> numQuery;
    for (int i = 1; i <= numQuery; ++i){
        int cmd, l, r, m;
        cin >> cmd;
        if(cmd == 1){
            vector<int> pos(numRot), val;
            for(int&v : pos) cin >> v;
            for (int j = 1; j < numRot; ++j) val.push_back(A[pos[j]]);
            val.push_back(A[pos[0]]);
            for (int j = 0; j < numRot; ++j){
                upd(1, 1, nArr, pos[j], nArr, val[j] - A[pos[j]]);
                A[pos[j]] = val[j];
            }
        }
        else{
            cin >> l >> r >> m;
            cout << query(1, 1, nArr, l + m - 1, r) - query(1, 1, nArr, l - 1, r - m) << '\n';
        }
    }
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();

}



Compilation message

Main.cpp:133:14: error: redefinition of 'constexpr const ll LINF'
  133 | constexpr ll LINF = (1ll << 60);
      |              ^~~~
Main.cpp:16:14: note: 'constexpr const ll LINF' previously defined here
   16 | constexpr ll LINF = (1ll << 60);
      |              ^~~~
Main.cpp:134:15: error: redefinition of 'constexpr const long long int INF'
  134 | constexpr int INF = (1ll << 30);
      |               ^~~
Main.cpp:17:15: note: 'constexpr const long long int INF' previously defined here
   17 | constexpr int INF = (1ll << 30);
      |               ^~~
Main.cpp:135:15: error: redefinition of 'constexpr const long long int Mod'
  135 | constexpr int Mod = 1e9 + 7;
      |               ^~~
Main.cpp:18:15: note: 'constexpr const long long int Mod' previously defined here
   18 | constexpr int Mod = 1e9 + 7;
      |               ^~~
Main.cpp:136:9: error: redefinition of 'std::mt19937 rng'
  136 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      |         ^~~
Main.cpp:19:9: note: 'std::mt19937 rng' previously declared here
   19 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      |         ^~~
Main.cpp:143:10: error: redefinition of 'template<class X, class Y> bool minimize(X&, const Y&)'
  143 |     bool minimize(X &x, const Y &y){
      |          ^~~~~~~~
Main.cpp:26:10: note: 'template<class X, class Y> bool minimize(X&, const Y&)' previously declared here
   26 |     bool minimize(X &x, const Y &y){
      |          ^~~~~~~~
Main.cpp:150:10: error: redefinition of 'template<class X, class Y> bool maximize(X&, const Y&)'
  150 |     bool maximize(X &x, const Y &y){
      |          ^~~~~~~~
Main.cpp:33:10: note: 'template<class X, class Y> bool maximize(X&, const Y&)' previously declared here
   33 |     bool maximize(X &x, const Y &y){
      |          ^~~~~~~~
Main.cpp:157:5: error: redefinition of 'long long int nArr'
  157 | int nArr, numRot, numQuery;
      |     ^~~~
Main.cpp:40:5: note: 'long long int nArr' previously declared here
   40 | int nArr, numRot, numQuery;
      |     ^~~~
Main.cpp:157:11: error: redefinition of 'long long int numRot'
  157 | int nArr, numRot, numQuery;
      |           ^~~~~~
Main.cpp:40:11: note: 'long long int numRot' previously declared here
   40 | int nArr, numRot, numQuery;
      |           ^~~~~~
Main.cpp:157:19: error: redefinition of 'long long int numQuery'
  157 | int nArr, numRot, numQuery;
      |                   ^~~~~~~~
Main.cpp:40:19: note: 'long long int numQuery' previously declared here
   40 | int nArr, numRot, numQuery;
      |                   ^~~~~~~~
Main.cpp:158:5: error: redefinition of 'long long int A [100005]'
  158 | int A[MAX];
      |     ^
Main.cpp:41:5: note: 'long long int A [100005]' previously declared here
   41 | int A[MAX];
      |     ^
Main.cpp:160:5: error: redefinition of 'long long int sum [100005]'
  160 | int sum[MAX];
      |     ^~~
Main.cpp:43:5: note: 'long long int sum [100005]' previously declared here
   43 | int sum[MAX];
      |     ^~~
Main.cpp:162:5: error: redefinition of 'long long int lz [400020]'
  162 | int lz[4 * MAX], st[4 * MAX];
      |     ^~
Main.cpp:45:5: note: 'long long int lz [400020]' previously declared here
   45 | int lz[4 * MAX], st[4 * MAX];
      |     ^~
Main.cpp:162:18: error: redefinition of 'long long int st [400020]'
  162 | int lz[4 * MAX], st[4 * MAX];
      |                  ^~
Main.cpp:45:18: note: 'long long int st [400020]' previously declared here
   45 | int lz[4 * MAX], st[4 * MAX];
      |                  ^~
Main.cpp:164:6: error: redefinition of 'void pushDown(long long int, long long int, long long int)'
  164 | void pushDown(int id, int l, int r){
      |      ^~~~~~~~
Main.cpp:47:6: note: 'void pushDown(long long int, long long int, long long int)' previously defined here
   47 | void pushDown(int id, int l, int r){
      |      ^~~~~~~~
Main.cpp:176:6: error: redefinition of 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)'
  176 | void upd(int id, int l, int r, int u, int v, int val){
      |      ^~~
Main.cpp:59:6: note: 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)' previously defined here
   59 | void upd(int id, int l, int r, int u, int v, int val){
      |      ^~~
Main.cpp:190:5: error: redefinition of 'long long int query(long long int, long long int, long long int, long long int, long long int)'
  190 | int query(int id, int l, int r, int u, int v){
      |     ^~~~~
Main.cpp:73:5: note: 'long long int query(long long int, long long int, long long int, long long int, long long int)' previously defined here
   73 | int query(int id, int l, int r, int u, int v){
      |     ^~~~~
Main.cpp:200:6: error: redefinition of 'void process()'
  200 | void process(void){
      |      ^~~~~~~
Main.cpp:83:6: note: 'void process()' previously defined here
   83 | void process(void){
      |      ^~~~~~~
Main.cpp:224:8: error: redefinition of 'int main()'
  224 | signed main(){
      |        ^~~~
Main.cpp:107:8: note: 'int main()' previously defined here
  107 | signed main(){
      |        ^~~~
Main.cpp: In function 'int main()':
Main.cpp:110:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |     freopen(name".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:111:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |     freopen(name".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~