ZJU 2671 Cryptography
Cryptography
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的更多相关文章
- ZOJ 2671 Cryptography 矩阵乘法+线段树
B - Cryptography Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Subm ...
- ZOJ - 2671 Cryptography(线段树+求区间矩阵乘积)
题意:已知n个矩阵(下标从1开始),求下标x~y区间矩阵的乘积.最多m次询问,n ( 1 <= n <= 30,000) and m ( 1 <= m <= 30,000). ...
- .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
.Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...
- ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学
ECC ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学,是目前已知的公钥体制中,对每比特所提供加密强度最高的一种体制.在软件注册保护方面起到很大的作用,一般的序列 ...
- "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法
.net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...
- System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型
这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...
- 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 ...
- [POJ2109]Power of Cryptography
[POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- springMVC入门截图
mvc在bs系统下的应用 ---------------------------------------------------- 在web.xml中配置前端控制器(系统提供的一个servlet类 ...
- “王者对战”之 MySQL 8 vs PostgreSQL 10
既然 MySQL 8 和 PostgreSQL 10 已经发布了,现在是时候回顾一下这两大开源关系型数据库是如何彼此竞争的. 在这些版本之前,人们普遍认为,Postgres 在功能集表现更出色,也因其 ...
- LCA【模板】
#include <algorithm> #include <cstdio> #include <vector> #define N 10015 using nam ...
- Libevent学习笔记
学习: /Users/baidu/Documents/Data/Interview/服务器-检索端/libevent参考手册(中文版).pdf 讲的不好.翻译的..
- HDU 2138
这题用MILLER测试应该是不可避免的. #include <iostream> #include <cstdio> #include <stdlib.h> #in ...
- [HTML5] Semantics for accessibility
For example, when we use checkbox, if we do like this: <div class="inline-control sign-up co ...
- cmd 进入mysql 小技巧
1.開始中找出执行:输入cmd 2.查找appserv所在盘,我的在D盘.所以接着输入:d: 3.在d盘中查找mysql所在文件夹:cd appserv\mysql\bin 4.再输入主机名.数据库名 ...
- SQL*PLUS命令的使用大全
Oracle的sql*plus是与oracle进行交互的客户端工具.在sql*plus中,可以运行sql*plus命令与sql*plus语句. 我们通常所说的DML.DDL.DCL语句都是sql*pl ...
- ThinkPHP5(目录,路径,模式设置,命名空间)
ThinkPHP是一个快速.兼容而且简单的轻量级国产PHP开发框架 目录结构 路径: http://www.tp5.comm/index.php/admin/index/index入口文件 pu ...
- <Android Framework 之路>Android5.1 Camera Framework(三)
上一次讲解了一下startPreview过程,主要是为了画出一条大致的从上到下的线条,今天我们看一下Camera在Framework的sendCommand和dataCallback,这部分属于衔接过 ...