답안 #795773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795773 2023-07-27T14:42:18 Z MISM06 ZIGZAG (INOI20_zigzag) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < int , pii > piii;
typedef pair < ll , ll > pll;
typedef pair < ll , pll > plll;
#define pb  push_back
#define all(x)  x.begin(), x.end()
#define sze     size()
#define F first
#define S second
#define kids    int mid = (tl + tr) >> 1, cl = v << 1, cr = v << 1 | 1;
#define wall__ cout << "________________________________________\n";

const ll N = 3e5 + 10, mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int rand (int l, int r) {
 
    return rng() % (r - l + 1) + l;
 
}

int n, q;
ll ar[N];

bool iss0 (int l, int r) {
    if (r - l + 1 == 1) return 1;
    int t = 0;
    for (int i = l + 1; i <= r; i++) {
        int s = -1;
        if (ar[i - 1] > ar[i]) s = 0;
        if (ar[i - 1] < ar[i]) s = 1;
        if (s != t) return 0;
        t ^= 1;
    }
}
bool iss0 (int l, int r) {
    if (r - l + 1 == 1) return 1;
    int t = 1;
    for (int i = l + 1; i <= r; i++) {
        int s = -1;
        if (ar[i - 1] > ar[i]) s = 0;
        if (ar[i - 1] < ar[i]) s = 1;
        if (s != t) return 0;
        t ^= 1;
    }
}
bool iss (int l, int r) {
    return iss0(l, r) | iss1(l, r);
}

ll calc (int l, int r) {
    ll res = 0;
    for (int i = l; i <= r; i++) {
        for (int j = i; j <= r; j++) if (iss(i, j)) ++ans;
    }
    cout << ans << '\n';
}
void mul (int l, int r) {
    for (int i = l; i <= r; i++) ar[i] *= -1ll;
}
void sum (ll x, int l, int r) {
    for (int i = l; i <= r; i++) ar[i] += x;
}

void solve () {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> ar[i];
    while(q--) {
        char t; int l, r; cin >> t >> l >> r;
        if (t == '+') {
            sum(x, l, r);
        } else if (t == '?') {
            cout << calc(l, r) << '\n';
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ts; cin >> ts;
    while(ts--) {
        solve();
    }
    return 0;
}

Compilation message

Main.cpp:41:6: error: redefinition of 'bool iss0(int, int)'
   41 | bool iss0 (int l, int r) {
      |      ^~~~
Main.cpp:30:6: note: 'bool iss0(int, int)' previously defined here
   30 | bool iss0 (int l, int r) {
      |      ^~~~
Main.cpp: In function 'bool iss(int, int)':
Main.cpp:53:25: error: 'iss1' was not declared in this scope; did you mean 'iss'?
   53 |     return iss0(l, r) | iss1(l, r);
      |                         ^~~~
      |                         iss
Main.cpp: In function 'll calc(int, int)':
Main.cpp:59:55: error: 'ans' was not declared in this scope; did you mean 'abs'?
   59 |         for (int j = i; j <= r; j++) if (iss(i, j)) ++ans;
      |                                                       ^~~
      |                                                       abs
Main.cpp:61:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   61 |     cout << ans << '\n';
      |             ^~~
      |             abs
Main.cpp:57:8: warning: unused variable 'res' [-Wunused-variable]
   57 |     ll res = 0;
      |        ^~~
Main.cpp:62:1: warning: no return statement in function returning non-void [-Wreturn-type]
   62 | }
      | ^
Main.cpp: In function 'void solve()':
Main.cpp:76:17: error: 'x' was not declared in this scope
   76 |             sum(x, l, r);
      |                 ^
Main.cpp: In function 'bool iss0(int, int)':
Main.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
   40 | }
      | ^
Main.cpp: In function 'bool iss0(int, int)':
Main.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
   51 | }
      | ^