답안 #791370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791370 2023-07-24T04:08:03 Z Amylopectin Fancy Fence (CEOI20_fancyfence) C++14
100 / 100
55 ms 9676 KB
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stdlib.h>
using namespace std;
const long long mxn = 1e6 + 10,mo = 1e9 + 7;
struct we
{
    long long hhei,idx;
};
bool cmp(const struct we &l,const struct we &r)
{
    return l.hhei < r.hhei;
}
set<long long> see = {};
struct we sot[mxn] = {};
long long hei[mxn] = {},wei[mxn] = {},chei[mxn] = {},enn[mxn] = {};
long long pot(long long l)
{
    long long cn = (l * (l+1)) / 2;
    return cn % mo;
}
int main()
{
    // freopen("input1.txt","r",stdin);
    long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
    set<long long> :: iterator f;
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&hei[i]);
        sot[i] = {hei[i],i};
    }
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&wei[i]);
        wei[i] += wei[i-1];
    }
    sort(sot,sot+n,cmp);
    see.insert(0);
    chei[0] = 0;
    enn[0] = n-1;
    su = 0;
    for(i=0; i<n; i++)
    {
        cn = sot[i].idx;
        f = see.upper_bound(cn);
        cl = (*(prev(f)));
        cen = enn[cl];
        fn = pot((wei[cen+1] - wei[cl])%mo);
        fm = (pot(hei[cn]) - pot(chei[cl]));
        if(fm < 0)
        {
            fm += mo;
        }
        su += (fn * fm) % mo;
        su %= mo;
        if(cn > cl)
        {
            chei[cl] = hei[cn];
            enn[cl] = cn-1;
        }
        if(cen > cn)
        {
            see.insert(cn+1);
            chei[cn+1] = hei[cn];
            enn[cn+1] = cen;
        }
    }
    printf("%lld\n",su);
    return 0;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:28:17: warning: unused variable 'j' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                 ^
fancyfence.cpp:28:21: warning: unused variable 'm' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                     ^
fancyfence.cpp:28:26: warning: unused variable 'cm' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                          ^~
fancyfence.cpp:28:38: warning: unused variable 'cr' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                                      ^~
fancyfence.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
fancyfence.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%lld",&hei[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
fancyfence.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%lld",&wei[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 14 ms 3540 KB Output is correct
4 Correct 28 ms 6264 KB Output is correct
5 Correct 33 ms 7024 KB Output is correct
6 Correct 27 ms 6064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 1108 KB Output is correct
3 Correct 23 ms 4708 KB Output is correct
4 Correct 24 ms 5356 KB Output is correct
5 Correct 25 ms 5408 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 4 ms 1132 KB Output is correct
4 Correct 18 ms 4724 KB Output is correct
5 Correct 24 ms 5480 KB Output is correct
6 Correct 25 ms 5416 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 1236 KB Output is correct
9 Correct 16 ms 3620 KB Output is correct
10 Correct 43 ms 9600 KB Output is correct
11 Correct 45 ms 9644 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 15 ms 3492 KB Output is correct
12 Correct 27 ms 6272 KB Output is correct
13 Correct 30 ms 7040 KB Output is correct
14 Correct 26 ms 6004 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1236 KB Output is correct
17 Correct 18 ms 4732 KB Output is correct
18 Correct 24 ms 5352 KB Output is correct
19 Correct 25 ms 5452 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 5 ms 1236 KB Output is correct
22 Correct 16 ms 3620 KB Output is correct
23 Correct 43 ms 9592 KB Output is correct
24 Correct 43 ms 9676 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 4 ms 980 KB Output is correct
31 Correct 4 ms 980 KB Output is correct
32 Correct 21 ms 3816 KB Output is correct
33 Correct 23 ms 3804 KB Output is correct
34 Correct 48 ms 7288 KB Output is correct
35 Correct 44 ms 7372 KB Output is correct
36 Correct 55 ms 7480 KB Output is correct
37 Correct 50 ms 7260 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 43 ms 7288 KB Output is correct
40 Correct 38 ms 7320 KB Output is correct
41 Correct 33 ms 6524 KB Output is correct
42 Correct 32 ms 6476 KB Output is correct