답안 #510747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
510747 2022-01-15T02:49:45 Z amukkalir 가로등 (APIO19_street_lamps) C++17
20 / 100
654 ms 9972 KB
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll; 
#define pii pair<int,int> 
#define fi first 
#define se second 
#define pb push_back 
#define mp make_pair

const int nax = 3e5; 
int n, q; 
int bit[nax+5]; 
int s[nax+5]; 
int mn[nax+5], st[nax+5]; 

void upd(int idx, int val) {
    for (int i = idx; i<=n; i += i & (-i)) {
        bit[i] += val; 
    }
}

int sum(int idx) {
    int ret = 0; 
    for(int i = idx; i>0; i -= (i & (-i))) {
        ret += bit[i]; 
    }
    return ret; 
}

int get(int l, int r) {
    return sum(r) - sum(l-1); 
}

signed main () {
    scanf("%d %d", &n,&q); 
    for(int i=1; i<=n; i++) {
        int x; 
        scanf("%1d", &x); 
        s[i] = x; 
    }

    for(int t=1; t<=q; t++) {
        string ts; cin >> ts; 
        if(ts == "query") {
            int a, b; scanf("%d %d", &a, &b); 
            int ans = 0; 
            if(s[a]) {
                ans = t - mn[a]; 
            } else {
                ans = t - mn[a] - (t-st[a]); 
            }

            printf("%d\n", ans); 

        } else {
            int x; scanf("%d", &x); 
            
            if(s[x]) st[x] = t; 
            else {
                mn[x] += t - st[x]; 
                st[x] = 0; 
            }
            s[x] ^= 1; 
        }
    }
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d %d", &n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~
street_lamps.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%1d", &x);
      |         ~~~~~^~~~~~~~~~~
street_lamps.cpp:45:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |             int a, b; scanf("%d %d", &a, &b);
      |                       ~~~~~^~~~~~~~~~~~~~~~~
street_lamps.cpp:56:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |             int x; scanf("%d", &x);
      |                    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 3092 KB Output is correct
2 Correct 578 ms 4732 KB Output is correct
3 Correct 390 ms 5188 KB Output is correct
4 Correct 487 ms 9528 KB Output is correct
5 Correct 496 ms 9972 KB Output is correct
6 Correct 405 ms 9336 KB Output is correct
7 Correct 636 ms 7964 KB Output is correct
8 Correct 654 ms 9364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -