Submission #582610

# Submission time Handle Problem Language Result Execution time Memory
582610 2022-06-24T07:28:26 Z 조영욱(#8372) Fibonacci representations (CEOI18_fib) C++17
30 / 100
253 ms 14916 KB
#include <bits/stdc++.h>
using namespace std;

int n;
const int mod=1e9+7;
vector<int> vec;
vector<int> pr;

struct Node {
    long long arr[2][2];
};

Node I;
const int sz=131072;
Node seg[sz*2];

Node merge(Node l,Node r) {
    Node ret;
    memset(ret.arr,0,sizeof(ret.arr));
    for(int i=0;i<2;i++) {
        for(int j=0;j<2;j++) {
            for(int k=0;k<2;k++) {
                ret.arr[i][j]+=l.arr[i][k]*r.arr[k][j];
                ret.arr[i][j]%=mod;
            }
        }
    }
    return ret;
}

Node sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
    if (r<nodel||l>noder) {
        return I;
    }
    if (l<=nodel&&noder<=r) {
        return seg[node];
    }
    int mid=(nodel+noder)/2;
    return merge(sum(l,r,node*2,nodel,mid),sum(l,r,node*2+1,mid+1,noder));
}

void update(int i,Node val) {
    i+=sz;
    seg[i]=val;
    while (i>1) {
        i/=2;
        seg[i]=merge(seg[i*2],seg[i*2+1]);
    }
}

int main(void) {
    scanf("%d",&n);
    I.arr[0][0]=1;
    I.arr[1][1]=1;
    for(int i=1;i<sz*2;i++) {
        seg[i]=I;
    }
    for(int ind=0;ind<n;ind++) {
        int x;
        scanf("%d",&x);
        vec.push_back(x);
        pr.push_back(x);
    }
    sort(pr.begin(),pr.end());
    set<int> s;
    s.insert(0);
    s.insert(1e9+7);
    for(int i=0;i<n;i++) {
        auto iter=s.lower_bound(vec[i]);
        auto pre=prev(iter);
        int nt=(*iter);
        Node temp;
        if (nt<=1000000000) {
            int nind=lower_bound(pr.begin(),pr.end(),nt)-pr.begin();
            temp.arr[0][0]=(nt-vec[i])/2+1;
            temp.arr[1][0]=((nt-vec[i])%2==0?mod-1:0);
            temp.arr[0][1]=1;
            temp.arr[1][1]=0;
            update(nind,temp);
        }
        int ind=lower_bound(pr.begin(),pr.end(),vec[i])-pr.begin();
        long long dist=vec[i]-(*pre);
        temp.arr[0][0]=dist/2+1;
        temp.arr[1][0]=(dist%2==0?mod-1:0);
        temp.arr[0][1]=1;
        temp.arr[1][1]=0;
        update(ind,temp);
        Node got=sum(0,sz-1);
        printf("%lld\n",(got.arr[0][0]+got.arr[1][0])%mod);
        s.insert(vec[i]);
    }
}

Compilation message

fib.cpp: In function 'int main()':
fib.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
fib.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d",&x);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8404 KB Output is correct
2 Correct 5 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8404 KB Output is correct
2 Correct 242 ms 14916 KB Output is correct
3 Correct 253 ms 14888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -