Cryptography

Time Limit: 5000ms
Memory Limit: 32768KB

This problem will be judged on ZJU. Original ID: 2671
64-bit integer IO format: %lld      Java class name: Main

 

Young cryptoanalyst Georgie is planning to break the new cipher invented by his friend Andie. To do this, he must make some linear transformations over the ring Zr = Z/rZ.

Each linear transformation is defined by 2×2 matrix. Georgie has a sequence of matrices A1 , A2 ,..., An . As a step of his algorithm he must take some segment Ai , Ai+1 , ..., Aj of the sequence and multiply some vector by a product Pi,j=Ai × Ai+1 × ... × Aj of the segment. He must do it for m various segments.

Help Georgie to determine the products he needs.

Input

There are several test cases in the input. The first line of each case contains r (1 <= r <= 10,000), n (1 <= n <= 30,000) and m (1 <= m <= 30,000). Next n blocks of two lines, containing two integer numbers ranging from 0 to r - 1 each, describe matrices. Blocks are separated with blank lines. They are followed by m pairs of integer numbers ranging from1 to n each that describe segments, products for which are to be calculated.
There is an empty line between cases.

Output

Print m blocks containing two lines each. Each line should contain two integer numbers ranging from 0 to r - 1 and define the corresponding product matrix.
There should be an empty line between cases.

Separate blocks with an empty line.

Sample

Input

3 4 4
0 1
0 0 2 1
1 2 0 0
0 2 1 0
0 2 1 4
2 3
1 3
2 2 Output
0 2
0 0 0 2
0 1 0 1
0 0 2 1
1 2

Source

 
解题:坑爹的线段树
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct Matrix {
int m[][];
};
struct node {
int lt,rt;
Matrix matrix;
};
node tree[maxn<<];
int r,n,m;
Matrix Multiplication(const Matrix &a,const Matrix &b) {
Matrix c;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
return c;
}
void read(Matrix &c) {
for(int i = ; i < ; ++i)
for(int j = ; j < ; ++j)
scanf("%d",&c.m[i][j]);
}
void build(int lt,int rt,int v) {
tree[v].lt = lt;
tree[v].rt = rt;
if(lt == rt) {
if(lt <= n) read(tree[v].matrix);
else {
tree[v].matrix.m[][] = ;
tree[v].matrix.m[][] = ;
tree[v].matrix.m[][] = ;
tree[v].matrix.m[][] = ;
}
return;
}
int mid = (lt+rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
tree[v].matrix = Multiplication(tree[v<<].matrix,tree[v<<|].matrix);
}
Matrix query(int lt,int rt,int v){
if(tree[v].lt == lt && tree[v].rt == rt) return tree[v].matrix;
int mid = (tree[v].lt + tree[v].rt)>>;
if(rt <= mid) return query(lt,rt,v<<);
else if(lt > mid) return query(lt,rt,v<<|);
else return Multiplication(query(lt,mid,v<<),query(mid+,rt,v<<|));
}
int main() {
bool cao = false;
while(~scanf("%d %d %d",&r,&n,&m)){
int k = log2(n) + ;
k = <<k;
build(,k,);
if(cao) puts("");
cao = true;
bool flag = false;
while(m--){
int s,t;
if(flag) puts("");
flag = true;
scanf("%d %d",&s,&t);
Matrix ans = query(s,t,);
for(int i = ; i < ; ++i)
printf("%d %d\n",ans.m[i][],ans.m[i][]);
}
}
return ;
}

ZJU 2671 Cryptography的更多相关文章

  1. ZOJ 2671 Cryptography 矩阵乘法+线段树

    B - Cryptography Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  2. ZOJ - 2671 Cryptography(线段树+求区间矩阵乘积)

    题意:已知n个矩阵(下标从1开始),求下标x~y区间矩阵的乘积.最多m次询问,n ( 1 <= n <= 30,000) and m ( 1 <= m <= 30,000). ...

  3. .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数

    .Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...

  4. ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学

    ECC ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学,是目前已知的公钥体制中,对每比特所提供加密强度最高的一种体制.在软件注册保护方面起到很大的作用,一般的序列 ...

  5. "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法

    .net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...

  6. System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型

    这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...

  7. Raspberry Pi 3 FAQ --- connect automatically to 'mirrors.zju.edu.cn' when downloading and how to accelerate download

    modify the software source: The software source is a place where several free application for linux ...

  8. [POJ2109]Power of Cryptography

    [POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...

  9. ACM: Gym 100935B Weird Cryptography - 简单的字符串处理

    Weird Cryptography Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. centos solr 部署到 tomcat 上

    一.安装 java1.7 环境 链接:https://pan.baidu.com/s/1ti6j9jD-RwUN5xl3bc3ZDw 密码:oc9a 二.下载 tomcat 并解压 链接:https: ...

  2. 【Web API系列教程】3.4 — 实战:处理数据(处理实体关系)

    前言 本部分描写叙述了EF怎样载入相关实体的细节,而且怎样在你的模型类中处理环形导航属性.(本部分预备了背景知识,而这不是完毕这个教程所必须的.你也能够跳到第五节) 预载入和延迟载入 预载入和延迟载入 ...

  3. [Performance] Optimize Paint and Composite for the website

    "Paint" is one of the most preference killer, it can easily cost more than 60fps, and once ...

  4. Visual C++ 经常使用快捷键

    大写和小写 Ctrl+Shift+U: 所有变为大写 Ctrl+U: 所有变为小写 凝视 Ctrl+K+Crtr+C: 凝视选定内容  Ctrl+K+Crtr+U: 取消选定凝视内容 折叠 折叠代码: ...

  5. linux 下password加密程序(能够用于替换shadow文件里的用户password)

    源代码例如以下: #include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]){ if(arg ...

  6. 刚接触Joomla,写一下瞎折腾的初感受~

    我这几天一直在苦苦寻找一款能够长期投靠的CMS产品,要求的是 1)必须支持命名空间 2)必须OOP + MVC分层 3)丰富分文档和使用群体,至少是出名的.免得哪一天他们解散了 4)-- 一開始我把目 ...

  7. USACO 2.2 Runaround Numbers

    Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81 ...

  8. Java-MyBatis-杂项:MyBatis根据数组、集合查询

    ylbtech-Java-MyBatis-杂项:MyBatis根据数组.集合查询 1.返回顶部 1. foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的 ...

  9. 12.Matlab神经网络工具箱

    概述: 1 人工神经网络介绍 2 人工神经元 3 MATLAB神经网络工具箱 4 感知器神经网络 5 感知器神经网络 5.1 设计实例分析 clear all; close all; P=[ ; ]; ...

  10. ubuntu下无法将iNode绑定到侧边栏的解决办法

    title: ubuntu下无法将iNode绑定到侧边栏的解决办法 toc: false date: 2018-09-01 17:43:52 categories: methods tags: ubu ...