답안 #319258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319258 2020-11-04T15:14:04 Z mohamedsobhi777 Worst Reporter 3 (JOI18_worst_reporter3) C++14
12 / 100
2000 ms 6176 KB
#include <bits/stdc++.h>

#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 5e5 + 7, mod = 1e9 + 7;
const ll inf = 2e18;

// How interesting!

int n, m;
int a[N];
ll per[N];

bool f(int i, int t, int l, int r)
{
        int p = per[i];
        int pos = -(i + 1);
        while (t - p >= 0)
                pos += p, t -= p;
        return pos >= l && pos <= r;
        //       int d = t / p;
        //     pos += p * d;
        return pos >= l && pos <= r;
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //freopen("in.in", "r", stdin);
        cin >> n >> m;

        for (int i = 0; i < n; ++i)
                cin >> a[i];
        per[0] = a[0];
        for (int i = 1; i < n; ++i)
                per[i] = ceil(1.0 * a[i] / per[i - 1]) * per[i - 1];

        for (int i = 0; i < m; ++i)
        {
                int x, y, z;
                cin >> x >> y >> z;
                int l = 0, r = n - 1;
                int ans1 = 0, ans2 = -1;
                int k = 0;
                while (l <= r)
                {
                        int mid = (l + r) >> 1;
                        if (f(mid, x, y, z))
                        {
                                ans1 = mid;
                                r = mid - 1;
                        }
                        else
                                l = mid + 1;
                }
                l = 0, r = n - 1;
                while (l <= r)
                {
                        int mid = (l + r) >> 1;
                        if (f(mid, x, y, z))
                        {
                                ans2 = mid;
                                l = mid + 1;
                        }
                        else
                                r = mid - 1;
                }
                ans1 = 1;
                ans2 = 0 ; 
                for (int j = 0; j < n; ++j)
                        ans2 += f(j, x, y, z);
                cout << ans2 - ans1 + 1 + (x >= y && x <= z) << "\n";
        }
        return 0;
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:60:21: warning: unused variable 'k' [-Wunused-variable]
   60 |                 int k = 0;
      |                     ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2093 ms 6176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 6 ms 364 KB Output is correct
6 Correct 5 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2093 ms 6176 KB Time limit exceeded
2 Halted 0 ms 0 KB -