답안 #1005537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005537 2024-06-22T15:12:39 Z underwaterkillerwhale 가로등 (APIO19_street_lamps) C++17
20 / 100
35 ms 6740 KB
//#ifdef ONLINE_JUDGE
//    #include "cyberland.h"
//#endif

#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N  = 3e5 + 2;
const ll Mod = 998244353;
const int szBL = 50;
const int INF = 1e9 + 7;
const int BASE = 137;

struct Query {
    int typ, u, v;
};

int n, Q;
int a[N];
Query qr[N];

namespace sub1 {
    bool check (int L, int R) {
        rep (i, L, R - 1) if (a[i] == 0) return 0;
        return 1;
    }
    void solution() {
        rep (i, 1, Q) {
            if (qr[i].typ == 0) {
                a[qr[i].u] ^= 1;
            }
            else {
                int L = qr[i].u, R = qr[i].v;
                int res = 0;
                reb (t, i, 1) {
                    if (qr[t].typ == 0) a[qr[t].u] ^= 1;
                    if (check(L, R)) {
                        ++res;
                    }
                }
                rep (t, 1, i) if (qr[t].typ == 0)  a[qr[t].u] ^= 1;
                cout << res <<"\n";
            }
        }
    }
}
namespace sub2 {
    int cnt[N];
    bool check () {
        rep (i, 1, n) if (qr[i].typ == 1 && (qr[i].u != qr[i].v + 1)) return 0;
        return 1;
    }
    void solution() {
        rep (i, 1, n) if (a[i] == 1) cnt[i] -= 1;
        rep (i, 1, Q) {
            if (qr[i].typ == 0) {
                a[i] ^= 1;
                if (a[i] == 0) cnt[i] += i;
                else cnt[i] -= i;
            }
            else {
                int pos = qr[i].u;
                int res = cnt[i];
                if (a[pos] == 1) res += i + 1;
                cout << res <<"\n";
            }
        }
    }
}
void solution() {
    cin >> n >> Q;
    string s; cin >> s;
    rep (i, 1, n) a[i] = s[i - 1] - '0';
    rep (i, 1, Q) {
        string s;
        cin >> s;
        if (s == "toggle") cin >> qr[i].u, qr[i].typ = 0;
        else cin >> qr[i].u >> qr[i].v, qr[i].typ = 1;
    }
    if (n <= 100 && Q <= 100) sub1 :: solution();
    else if (sub2 :: check()) sub2 :: solution();
//    else sub3 :: solution();
}
#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    file ("PAINT");
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}

/*
7
1 2 3 1 2 1 3
1
4 4 30
3
1 1 2 1
0 1 5
0 2 5
1 3 2
2 3 4


3 2
0 1 5
0 2 5
1
1 2

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2516 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 6740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2516 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Incorrect 35 ms 6740 KB Output isn't correct
9 Halted 0 ms 0 KB -