답안 #81231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81231 2018-10-24T07:32:12 Z ngot23 Programiranje (COCI17_programiranje) C++11
80 / 80
60 ms 11916 KB
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define Task ""
using namespace std;
const int N=50005;
int bit[26][N], n;
string s;

void update(int t, int node) {
    while(node<=n) {
        ++bit[t][node];
        node+=node&(-node);
    }
}

int get(int t, int node) {
    int ret=0;
    while(node>0) {
        ret+=bit[t][node];
        node-=node&(-node);
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> s;
    n=s.size();
    rep(i, 0, s.size()-1) {
        int xx=s[i]-'a';
        update(xx, i+1);
    }
    int Q;
    cin >> Q;
    while(Q--) {
        int x, y, u, v;
        cin >> x >> y >> u >> v;
        if(y-x!=v-u) { cout << "NE" << '\n'; continue; }
        bool ok=1;
        rep(i, 0, 25) {
            int num1=get(i, y)-get(i, x-1);
            int num2=get(i, v)-get(i, u-1);
            if(num1!=num2) { ok=0; break; }
        }
        cout << (ok?"DA":"NE") << '\n';
    }
    return 0;
}

Compilation message

programiranje.cpp: In function 'int main()':
programiranje.cpp:2:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
                                       ^
programiranje.cpp:31:5: note: in expansion of macro 'rep'
     rep(i, 0, s.size()-1) {
     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 892 KB Output is correct
3 Correct 3 ms 948 KB Output is correct
4 Correct 3 ms 948 KB Output is correct
5 Correct 3 ms 1040 KB Output is correct
6 Correct 57 ms 7520 KB Output is correct
7 Correct 57 ms 8604 KB Output is correct
8 Correct 60 ms 9600 KB Output is correct
9 Correct 59 ms 10744 KB Output is correct
10 Correct 54 ms 11916 KB Output is correct