Submission #848288


Source Code Expand

Copy
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;

long long q[100005];
int ql[100005];
int ptr;
long long res[100005];
map<long long, long long> cnt;

int main(){
    int N, Q;
    scanf("%d%d", &N, &Q);
    ql[ptr++] = 0;
    q[0] = N;
    for(int i=1; i<=Q; i++){
        scanf("%lld", &q[i]);
        while(ptr > 0 && q[ql[ptr-1]] >= q[i]) ql[ptr-1] = 0, ptr--;
        ql[ptr++] = i;
    }
    ptr--;
    cnt[q[Q]] = 1;
    map<long long, long long>::iterator it = cnt.end();
    it--;
    ptr--;
    //printf("%d %d\n", ql[ptr], ptr);
    while(ptr >= 0){
        long long base = q[ql[ptr]];
        while(it->first > q[ql[ptr]]){
            cnt[base] += (it->second) * ((it->first)/base);
            cnt[(it->first)%base] += it->second;
            it->second = 0;
            it--;
        }
        ptr--;
    }
    for(auto ite : cnt){
        //printf("!%lld %lld\n", ite.first, ite.second);
        if(ite.first > N) break;
        res[ite.first] = ite.second;
    }
    for(int i=N; i>=1; i--){
        res[i] += res[i+1];
    }
    for(int i=1; i<=N; i++) printf("%lld\n", res[i]);
    return 0;
}

Submission Info

Submission Time
Task E - Sequential operations on Sequence
User zoomswk
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 1187 Byte
Status AC
Exec Time 553 ms
Memory 25344 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &Q);
                          ^
./Main.cpp:18:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &q[i]);
                             ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1400 / 1400
Status
AC × 2
AC × 38
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 60 ms 3072 KB
02.txt AC 61 ms 3200 KB
03.txt AC 62 ms 3200 KB
04.txt AC 61 ms 3200 KB
05.txt AC 61 ms 3200 KB
06.txt AC 258 ms 21248 KB
07.txt AC 304 ms 25344 KB
08.txt AC 274 ms 22784 KB
09.txt AC 292 ms 24320 KB
10.txt AC 257 ms 20736 KB
11.txt AC 235 ms 19328 KB
12.txt AC 285 ms 24064 KB
13.txt AC 284 ms 24704 KB
14.txt AC 251 ms 20736 KB
15.txt AC 239 ms 19712 KB
16.txt AC 273 ms 22400 KB
17.txt AC 272 ms 23168 KB
18.txt AC 257 ms 21632 KB
19.txt AC 226 ms 18304 KB
20.txt AC 270 ms 22528 KB
21.txt AC 553 ms 24320 KB
22.txt AC 492 ms 24576 KB
23.txt AC 323 ms 16000 KB
24.txt AC 100 ms 9728 KB
25.txt AC 102 ms 9600 KB
26.txt AC 90 ms 8576 KB
27.txt AC 36 ms 2048 KB
28.txt AC 36 ms 2048 KB
29.txt AC 36 ms 2048 KB
30.txt AC 38 ms 2048 KB
31.txt AC 4 ms 256 KB
32.txt AC 19 ms 1152 KB
33.txt AC 3 ms 256 KB
34.txt AC 27 ms 2432 KB
35.txt AC 4 ms 256 KB
36.txt AC 4 ms 256 KB
s1.txt AC 4 ms 256 KB
s2.txt AC 4 ms 256 KB