Submission #932674

# Submission time Handle Problem Language Result Execution time Memory
932674 2024-02-24T02:47:33 Z VinhLuu Street Lamps (APIO19_street_lamps) C++17
60 / 100
136 ms 33952 KB
// REPUTATION RATING =

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 3e5 + 5;
//const int oo = 1e9;
const int mod = 1e9 + 7;

int n, q, a[N], L[N], R[N], X[N];
string s, T[N];

namespace sub1{
    int m[105][105];
    void solve(){
        for(int i = 1; i <= n; i ++) m[1][i] = a[i];
        for(int t = 1; t <= q; t ++){
            string type; cin >> type;
            if(type[0] == 't'){
                int x; cin >> x;
                a[x] = 1 - a[x];
            }else{
                int l, r, ans = 0; cin >> l >> r;
                for(int j = 1; j <= t; j ++){
                    bool ff = true;
                    for(int i = l; i < r; i ++) if(m[j][i] == 0){
                        ff = false;
                        break;
                    }
                    ans += ff;
                }
                cout << ans << "\n";
            }
            for(int i = 1;i <= n; i ++) m[t + 1][i] = a[i];
        }
    }
}

namespace sub2{
    bool on[N];
    int cnt[N], f[N];
    void solve(){
        for(int i = 1; i <= n; i ++){
            if(a[i] == 1){
                f[i] = 1;
                on[i] = true;
            }else{
                on[i] = false;
                f[i] = -1;
            }
        }
        for(int t = 1; t <= q; t ++){
            string type = T[t];
            if(type[0] == 't'){
                int x = X[t];
                if(on[x]){
                    cnt[x] += t - f[x] + 1;
                }else{
                    f[x] = t + 1;
                }
                on[x] = 1 - on[x];
            }else{
                int l = L[t], r = R[t], ans = 0; cin >> l >> r;
                if(on[l]) cout << cnt[l] + t - f[l] + 1 << "\n";
                else cout << cnt[l] << "\n";
            }
        }
    }
}

namespace sub3{
    bool on[N];
    int cnt[N], f[N], st[N << 1];
    int get(int l,int r){
        r++;
        int ret = 1;
        for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){
            if(l & 1) ret = max(ret, st[l ++]);
            if(r & 1) ret = max(ret, st[-- r]);
        }
        return ret;
    }
    void solve(){
        for(int i = 1; i <= n; i ++){
            if(a[i] == 1){
                f[i] = 1;
                on[i] = true;
            }else{
                on[i] = false;
                f[i] = 1e9;
            }
        }
        for(int t = 1; t <= q; t ++){
            string type = T[t];
            if(type[0] == 't'){
                int x = X[t]; //cin >> x;
                f[x] = t + 1;
            }
        }
        for(int i = 1; i <= n; i ++) st[i + n - 1] = f[i];
        for(int i = n - 1; i >= 1; i --) st[i] = max(st[i << 1], st[i << 1|1]);
        for(int t = 1; t <= q; t ++){
            string type = T[t];
            if(type[0] == 't') continue;

            int l = L[t], r = R[t], ans = 0; cin >> l >> r;
            int u = get(l, r - 1);
            if(u > t) cout << 0 << "\n";
            else cout << t - u + 1 << "\n";
        }
    }
}


#define LOCAL

#ifdef LOCAL
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }

    cin >> n >> q >> s;
    for(int i = 1; i <= n; i ++) a[i] = s[i - 1] - '0';
    if(n <= 100 && q <= 100)
        sub1 :: solve();
    else{
        bool gg = true;
        for(int i = 1; i <= q; i ++) {
            cin >> T[i];
            if(T[i][0] == 't') cin >> X[i];
            else{
                cin >> L[i] >> R[i];
                if(R[i] - L[i] > 1) gg = false;
            }
        }
        if(gg) sub2 :: solve();
        else
            sub3 :: solve();
    }
}
#endif // LOCAL

Compilation message

street_lamps.cpp: In function 'void sub2::solve()':
street_lamps.cpp:70:41: warning: unused variable 'ans' [-Wunused-variable]
   70 |                 int l = L[t], r = R[t], ans = 0; cin >> l >> r;
      |                                         ^~~
street_lamps.cpp: In function 'void sub3::solve()':
street_lamps.cpp:113:37: warning: unused variable 'ans' [-Wunused-variable]
  113 |             int l = L[t], r = R[t], ans = 0; cin >> l >> r;
      |                                     ^~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 24148 KB Output is correct
2 Correct 62 ms 27304 KB Output is correct
3 Correct 64 ms 27988 KB Output is correct
4 Correct 73 ms 31704 KB Output is correct
5 Correct 78 ms 32276 KB Output is correct
6 Correct 68 ms 31464 KB Output is correct
7 Correct 85 ms 32532 KB Output is correct
8 Correct 88 ms 33952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20828 KB Output is correct
2 Correct 4 ms 20984 KB Output is correct
3 Correct 5 ms 20828 KB Output is correct
4 Correct 4 ms 20828 KB Output is correct
5 Correct 54 ms 30136 KB Output is correct
6 Correct 73 ms 30436 KB Output is correct
7 Correct 99 ms 30608 KB Output is correct
8 Correct 131 ms 32148 KB Output is correct
9 Correct 68 ms 23788 KB Output is correct
10 Correct 74 ms 23892 KB Output is correct
11 Correct 75 ms 23892 KB Output is correct
12 Correct 136 ms 30804 KB Output is correct
13 Correct 128 ms 32184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20828 KB Output is correct
2 Incorrect 4 ms 20828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 3 ms 12636 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 60 ms 24148 KB Output is correct
9 Correct 62 ms 27304 KB Output is correct
10 Correct 64 ms 27988 KB Output is correct
11 Correct 73 ms 31704 KB Output is correct
12 Correct 78 ms 32276 KB Output is correct
13 Correct 68 ms 31464 KB Output is correct
14 Correct 85 ms 32532 KB Output is correct
15 Correct 88 ms 33952 KB Output is correct
16 Correct 4 ms 20828 KB Output is correct
17 Correct 4 ms 20984 KB Output is correct
18 Correct 5 ms 20828 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Correct 54 ms 30136 KB Output is correct
21 Correct 73 ms 30436 KB Output is correct
22 Correct 99 ms 30608 KB Output is correct
23 Correct 131 ms 32148 KB Output is correct
24 Correct 68 ms 23788 KB Output is correct
25 Correct 74 ms 23892 KB Output is correct
26 Correct 75 ms 23892 KB Output is correct
27 Correct 136 ms 30804 KB Output is correct
28 Correct 128 ms 32184 KB Output is correct
29 Correct 4 ms 20828 KB Output is correct
30 Incorrect 4 ms 20828 KB Output isn't correct
31 Halted 0 ms 0 KB -