Submission #1798273


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef pair<int,int> pii;
// tree <pii,null_type,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 400005;
const int M = 205;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps = 1e-8;
int n,m;
int dp[N];
int s[N],pre[N];
std::vector<int> G[N];
class SegmentTree {
  public:
    SegmentTree(int size, int value):
        m_size(size),
        m_data(size * 2, value) {}
 
    void update(int position, int value) {
        for (position += m_size; position; position /= 2)
            m_data[position] = min(m_data[position], value);
    }
 
    int query(int from, int to) {
        int answer = numeric_limits<int>::max();
        for (from += m_size, to += m_size; from < to; from /= 2, to /= 2) {
            if (from & 1)
                answer = min(answer, m_data[from++]);
            if (to & 1)
                answer = min(answer, m_data[--to]);
        }
        return answer;
    }
 
  private:
    int m_size;
    vector<int> m_data;
};
void ini()
{
    fill(pre,pre+n+1,0);
    fill(dp,dp+n+1,n);
    for (int i=0;i<=n;i++)    
        G[i].clear();
}
int main()
{
    while (~scanf("%d",&n))
    {
        ini();
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&s[i]);
            pre[i] = pre[i-1]+(1-s[i]);
        }
        scanf("%d",&m);
        for (int i=0;i<m;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            G[a].push_back(b);
        }
        int ans = 0;
        dp[0] = 0;
        SegmentTree S(n+1,n);
        for (int i=1;i<=n;i++)
        {
            dp[i] = min(dp[i],dp[i-1]+s[i]);
            S.update(i-1,dp[i-1]-pre[i-1]);
            for (int j=0;j<G[i].size();j++)
            {
                int l = i;
                int r = G[i][j];
                int tmp = S.query(l-1,r);
                dp[r] = min(dp[r],tmp+pre[r]);
                S.update(r,tmp);
            }
            // cout<<"bug "<<endl;
            // for (int i=1;i<=n;i++)
            //     cout<<dp[i]<<" ";
            // cout<<endl;
            // for (int i=1;i<=n;i++)
            //     cout<<S.query(i-1,i)<<" ";
            // cout<<endl;
        }
        ans = dp[n];
        printf("%d\n", ans);
    }
    return 0;
}
 
/*
 
3
1 0 1
1
1 3

3
1 0 1
2
1 1
3 3

3
1 0 1
2
1 1
2 3
 
5
0 1 0 1 0
1
1 5
 
9
0 1 0 1 1 1 0 1 0
3
1 4
5 8
6 7
 
15
1 1 0 0 0 0 0 0 1 0 1 1 1 0 0
9
4 10
13 14
1 7
4 14
9 11
2 6
7 8
3 12
7 13
 
10
0 0 0 1 0 0 1 1 1 0
7
1 4
2 5
1 3
6 7
9 9
1 5
7 9
 
*/

Submission Info

Submission Time
Task F - NRE
User GG_GG
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 3047 Byte
Status AC
Exec Time 125 ms
Memory 18816 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:70:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&s[i]);
                              ^
./Main.cpp:73:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&m);
                       ^
./Main.cpp:77:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&a,&b);
                                ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 7
AC × 127
Set Name Test Cases
Sample example_0, example_1, example_2, example_3, example_4, example_5, example_6
All cent_0, cent_1, cent_2, cent_3, cent_4, cent_5, cent_6, cent_7, cent_8, cent_9, example_0, example_1, example_2, example_3, example_4, example_5, example_6, full_0, full_1, full_10, full_11, full_12, full_13, full_14, full_15, full_16, full_17, full_18, full_19, full_2, full_3, full_4, full_5, full_6, full_7, full_8, full_9, maxrand_0, maxrand_1, maxrand_10, maxrand_11, maxrand_12, maxrand_13, maxrand_14, maxrand_15, maxrand_16, maxrand_17, maxrand_18, maxrand_19, maxrand_2, maxrand_20, maxrand_21, maxrand_22, maxrand_23, maxrand_24, maxrand_25, maxrand_26, maxrand_27, maxrand_28, maxrand_29, maxrand_3, maxrand_4, maxrand_5, maxrand_6, maxrand_7, maxrand_8, maxrand_9, rand_0, rand_1, rand_10, rand_11, rand_12, rand_13, rand_14, rand_15, rand_16, rand_17, rand_18, rand_19, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9, small_0, small_1, small_2, small_3, small_4, small_5, small_6, small_7, small_8, small_9, smallwidth_0, smallwidth_1, smallwidth_10, smallwidth_11, smallwidth_12, smallwidth_13, smallwidth_14, smallwidth_15, smallwidth_16, smallwidth_17, smallwidth_18, smallwidth_19, smallwidth_2, smallwidth_20, smallwidth_21, smallwidth_22, smallwidth_23, smallwidth_24, smallwidth_25, smallwidth_26, smallwidth_27, smallwidth_28, smallwidth_29, smallwidth_3, smallwidth_4, smallwidth_5, smallwidth_6, smallwidth_7, smallwidth_8, smallwidth_9
Case Name Status Exec Time Memory
cent_0 AC 101 ms 17528 KB
cent_1 AC 112 ms 18304 KB
cent_2 AC 99 ms 16884 KB
cent_3 AC 108 ms 17788 KB
cent_4 AC 106 ms 17912 KB
cent_5 AC 97 ms 17012 KB
cent_6 AC 108 ms 17784 KB
cent_7 AC 104 ms 17400 KB
cent_8 AC 113 ms 18432 KB
cent_9 AC 104 ms 17140 KB
example_0 AC 5 ms 12544 KB
example_1 AC 5 ms 12544 KB
example_2 AC 5 ms 12544 KB
example_3 AC 5 ms 12544 KB
example_4 AC 5 ms 12544 KB
example_5 AC 5 ms 12544 KB
example_6 AC 5 ms 12544 KB
full_0 AC 28 ms 14848 KB
full_1 AC 108 ms 18688 KB
full_10 AC 28 ms 14976 KB
full_11 AC 115 ms 18688 KB
full_12 AC 28 ms 14976 KB
full_13 AC 110 ms 18688 KB
full_14 AC 28 ms 14848 KB
full_15 AC 111 ms 18688 KB
full_16 AC 28 ms 14848 KB
full_17 AC 111 ms 18688 KB
full_18 AC 28 ms 14976 KB
full_19 AC 111 ms 18688 KB
full_2 AC 29 ms 14976 KB
full_3 AC 109 ms 18688 KB
full_4 AC 28 ms 14976 KB
full_5 AC 109 ms 18688 KB
full_6 AC 28 ms 14848 KB
full_7 AC 107 ms 18688 KB
full_8 AC 28 ms 14976 KB
full_9 AC 109 ms 18688 KB
maxrand_0 AC 28 ms 14848 KB
maxrand_1 AC 116 ms 18432 KB
maxrand_10 AC 28 ms 14848 KB
maxrand_11 AC 118 ms 18432 KB
maxrand_12 AC 28 ms 14976 KB
maxrand_13 AC 115 ms 18432 KB
maxrand_14 AC 28 ms 14848 KB
maxrand_15 AC 118 ms 18432 KB
maxrand_16 AC 29 ms 14848 KB
maxrand_17 AC 114 ms 18432 KB
maxrand_18 AC 28 ms 14976 KB
maxrand_19 AC 125 ms 18432 KB
maxrand_2 AC 28 ms 14848 KB
maxrand_20 AC 28 ms 14848 KB
maxrand_21 AC 117 ms 18432 KB
maxrand_22 AC 29 ms 14976 KB
maxrand_23 AC 115 ms 18432 KB
maxrand_24 AC 28 ms 14976 KB
maxrand_25 AC 118 ms 18432 KB
maxrand_26 AC 28 ms 14976 KB
maxrand_27 AC 114 ms 18432 KB
maxrand_28 AC 28 ms 14848 KB
maxrand_29 AC 113 ms 18432 KB
maxrand_3 AC 114 ms 18432 KB
maxrand_4 AC 28 ms 14848 KB
maxrand_5 AC 119 ms 18432 KB
maxrand_6 AC 28 ms 14848 KB
maxrand_7 AC 115 ms 18432 KB
maxrand_8 AC 28 ms 14848 KB
maxrand_9 AC 115 ms 18432 KB
rand_0 AC 115 ms 18432 KB
rand_1 AC 61 ms 14720 KB
rand_10 AC 112 ms 18432 KB
rand_11 AC 43 ms 15360 KB
rand_12 AC 113 ms 18432 KB
rand_13 AC 82 ms 16640 KB
rand_14 AC 115 ms 18432 KB
rand_15 AC 48 ms 14208 KB
rand_16 AC 119 ms 18432 KB
rand_17 AC 62 ms 15488 KB
rand_18 AC 121 ms 18432 KB
rand_19 AC 99 ms 17792 KB
rand_2 AC 115 ms 18432 KB
rand_3 AC 81 ms 15104 KB
rand_4 AC 113 ms 18432 KB
rand_5 AC 50 ms 13824 KB
rand_6 AC 112 ms 18432 KB
rand_7 AC 67 ms 15232 KB
rand_8 AC 115 ms 18432 KB
rand_9 AC 31 ms 14848 KB
small_0 AC 5 ms 12544 KB
small_1 AC 5 ms 12544 KB
small_2 AC 5 ms 12544 KB
small_3 AC 5 ms 12544 KB
small_4 AC 5 ms 12544 KB
small_5 AC 5 ms 12544 KB
small_6 AC 5 ms 12544 KB
small_7 AC 5 ms 12544 KB
small_8 AC 5 ms 12544 KB
small_9 AC 5 ms 12544 KB
smallwidth_0 AC 28 ms 14848 KB
smallwidth_1 AC 105 ms 18816 KB
smallwidth_10 AC 28 ms 14848 KB
smallwidth_11 AC 98 ms 18816 KB
smallwidth_12 AC 28 ms 14848 KB
smallwidth_13 AC 117 ms 18816 KB
smallwidth_14 AC 28 ms 14848 KB
smallwidth_15 AC 100 ms 18816 KB
smallwidth_16 AC 28 ms 14848 KB
smallwidth_17 AC 107 ms 18816 KB
smallwidth_18 AC 28 ms 14848 KB
smallwidth_19 AC 98 ms 18816 KB
smallwidth_2 AC 28 ms 14976 KB
smallwidth_20 AC 28 ms 14848 KB
smallwidth_21 AC 105 ms 18816 KB
smallwidth_22 AC 28 ms 14848 KB
smallwidth_23 AC 96 ms 18816 KB
smallwidth_24 AC 28 ms 14848 KB
smallwidth_25 AC 105 ms 18816 KB
smallwidth_26 AC 28 ms 14848 KB
smallwidth_27 AC 95 ms 18816 KB
smallwidth_28 AC 28 ms 14848 KB
smallwidth_29 AC 106 ms 18816 KB
smallwidth_3 AC 100 ms 18816 KB
smallwidth_4 AC 28 ms 14848 KB
smallwidth_5 AC 109 ms 18816 KB
smallwidth_6 AC 28 ms 14848 KB
smallwidth_7 AC 95 ms 18816 KB
smallwidth_8 AC 28 ms 14848 KB
smallwidth_9 AC 107 ms 18816 KB