답안 #919913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919913 2024-02-01T20:34:25 Z CyberCow Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
28 ms 5584 KB
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((x).size())
typedef long long ll;
using namespace std;
mt19937 rnd(348502);
const ll N = 2010;
ll mod = 1e9 + 7;

void solve()
{
    ll x, y, a, b;
    int i, n;
    cin >> n;
    vector<pair<ll, ll>> v;
    for ( i = 0; i < n; i++)
    {
        cin >> x;
        v.push_back({ x, 0 });
    }
    for ( i = 0; i < n; i++)
    {
        cin >> x;
        v[i].second = x;
    }
    ll qan = 0, ans = 0;
    stack<pair<ll, ll>> s;
    for ( i = 0; i < n; i++)
    {
        ll ne = 0;
        ans = (ans + (v[i].first * (v[i].first - 1) / 2 + v[i].first) % mod * ((v[i].second * (v[i].second - 1) / 2 + v[i].second) % mod) % mod) % mod;
        while (!s.empty() && s.top().first > v[i].first)
        {
            qan = (mod + (qan - (s.top().first * (s.top().first - 1) / 2+ s.top().first) % mod * s.top().second % mod) % mod) % mod;
            qan = (qan + (v[i].first * (v[i].first - 1) / 2 + v[i].first) % mod * s.top().second) % mod;
            ne = (ne + s.top().second) % mod;
            s.pop();
        }
        ans = (ans + qan * v[i].second) % mod;
        qan = (qan + (v[i].first * (v[i].first - 1) / 2 + v[i].first) % mod * v[i].second % mod) % mod;
        s.push({ v[i].first, (ne + v[i].second) % mod });
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll tt = 1;
    //cout << (mod + -10000010 % mod) % mod;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Compilation message

fancyfence.cpp: In function 'void solve()':
fancyfence.cpp:31:11: warning: unused variable 'y' [-Wunused-variable]
   31 |     ll x, y, a, b;
      |           ^
fancyfence.cpp:31:14: warning: unused variable 'a' [-Wunused-variable]
   31 |     ll x, y, a, b;
      |              ^
fancyfence.cpp:31:17: warning: unused variable 'b' [-Wunused-variable]
   31 |     ll x, y, a, b;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 10 ms 2004 KB Output is correct
4 Correct 19 ms 4304 KB Output is correct
5 Correct 22 ms 3784 KB Output is correct
6 Correct 22 ms 3524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 988 KB Output is correct
3 Correct 14 ms 3284 KB Output is correct
4 Correct 24 ms 5424 KB Output is correct
5 Correct 23 ms 5576 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 3 ms 992 KB Output is correct
4 Correct 12 ms 3032 KB Output is correct
5 Correct 26 ms 5572 KB Output is correct
6 Correct 24 ms 5584 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 3 ms 992 KB Output is correct
9 Correct 13 ms 3284 KB Output is correct
10 Correct 24 ms 5324 KB Output is correct
11 Correct 24 ms 5580 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 11 ms 2004 KB Output is correct
12 Correct 20 ms 4304 KB Output is correct
13 Correct 20 ms 3784 KB Output is correct
14 Correct 20 ms 3280 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 12 ms 3028 KB Output is correct
18 Correct 24 ms 5576 KB Output is correct
19 Correct 24 ms 5576 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 3 ms 988 KB Output is correct
22 Correct 12 ms 3028 KB Output is correct
23 Correct 24 ms 5320 KB Output is correct
24 Correct 24 ms 5576 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 548 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 3 ms 860 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 13 ms 2260 KB Output is correct
33 Correct 14 ms 2260 KB Output is correct
34 Correct 26 ms 3792 KB Output is correct
35 Correct 25 ms 3784 KB Output is correct
36 Correct 28 ms 4048 KB Output is correct
37 Correct 28 ms 4040 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 28 ms 4040 KB Output is correct
40 Correct 28 ms 4048 KB Output is correct
41 Correct 28 ms 4048 KB Output is correct
42 Correct 28 ms 4560 KB Output is correct